Skip to content

Commit

Permalink
Remove page-level omTaggingLabels tag when converting legacy tags
Browse files Browse the repository at this point in the history
  • Loading branch information
stevencohn committed Aug 10, 2024
1 parent da744fe commit 54a81ef
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions OneMore/Commands/Tagging/LegacyTaggingConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ private async Task<bool> UpgradeLegacyTags(ProgressDialog dialog, CancellationTo
break;
}

var updated = false;

// update legacy tags in the tagging bank by prefixing them with a hashtag...

var bank = page.Root.Descendants(ns + "Meta")
.FirstOrDefault(e => e.Attribute("name").Value == MetaNames.TaggingBank);

Expand Down Expand Up @@ -235,21 +239,37 @@ private async Task<bool> UpgradeLegacyTags(ProgressDialog dialog, CancellationTo

// clear the tagging bank meta element value
flag.Value = string.Empty;
updated = true;
}

// delete the omTaggingLabels Meta element by removing its content attribute
page.Root.Elements(ns + "Meta")
.Where(e => e.Attribute("name").Value == MetaNames.TaggingLabels &&
e.Attribute("content") != null)
.Select(e => e.Attribute("content"))
.Remove();
// remove the omTaggingLabels Meta element from the page...

if (!token.IsCancellationRequested)
if (!token.IsCancellationRequested)
{
// delete the omTaggingLabels Meta element by removing its content attribute,
// should only be one
var rogue = page.Root.Elements(ns + "Meta")
.FirstOrDefault(e => e.Attribute("name").Value == MetaNames.TaggingLabels &&
e.Attribute("content") != null);

if (rogue is not null &&
rogue.Attribute("content") is XAttribute content)
{
await one.Update(page);
PagesConverted++;
logger.Verbose($"removing meta on {page.PageId} \"{page.Title}\"");
content.Remove();
updated = true;
}
}

// save page if any updates...

if (!token.IsCancellationRequested && updated)
{
logger.Verbose($"saving page {page.PageId} \"{page.Title}\"");
await one.Update(page);
PagesConverted++;
}

dialog.Increment();
}

Expand Down

0 comments on commit 54a81ef

Please sign in to comment.