Skip to content

Commit

Permalink
Only set supported fields in frontmatter
Browse files Browse the repository at this point in the history
  • Loading branch information
Ole Eskild Steensen committed Mar 15, 2022
1 parent de9c530 commit fdc4e24
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
26 changes: 12 additions & 14 deletions Publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,39 +169,37 @@ export default class Publisher {
const cachedFrontMatter = this.metadataCache.getCache(path).frontmatter;
const frontMatter = { ...cachedFrontMatter };

const publishedFrontMatter:any = {};
if (frontMatter && frontMatter["dg-permalink"]) {
frontMatter["permalink"] = frontMatter["dg-permalink"];
if (!frontMatter["permalink"].endsWith("/")) {
frontMatter["permalink"] += "/";
publishedFrontMatter["permalink"] = frontMatter["dg-permalink"];
if (!publishedFrontMatter["permalink"].endsWith("/")) {
publishedFrontMatter["permalink"] += "/";
}
if (!frontMatter["permalink"].startsWith("/")) {
frontMatter["permalink"] = "/" + frontMatter["permalink"];
if (!publishedFrontMatter["permalink"].startsWith("/")) {
publishedFrontMatter["permalink"] = "/" + publishedFrontMatter["permalink"];
}
} else {
const noteUrlPath = generateUrlPath(path);
frontMatter["permalink"] = "/" + noteUrlPath;
publishedFrontMatter["permalink"] = "/" + noteUrlPath;
}

if (frontMatter && frontMatter["dg-home"]) {
const tags = frontMatter["tags"];
if (tags) {
if (typeof (tags) === "string") {
frontMatter["tags"] = [tags, "gardenEntry"];
publishedFrontMatter["tags"] = [tags, "gardenEntry"];
} else {
frontMatter["tags"] = [...tags, "gardenEntry"];
publishedFrontMatter["tags"] = [...tags, "gardenEntry"];
}
} else {
frontMatter["tags"] = "gardenEntry";
publishedFrontMatter["tags"] = "gardenEntry";
}

}
//replace frontmatter at start of file

const replaced = text.replace(/^---\n([\s\S]*?)\n---/g, (match, p1) => {
const copy = { ...frontMatter };
delete copy["position"];
delete copy["end"];
const frontMatterString = JSON.stringify(copy);
const frontMatterString = JSON.stringify(publishedFrontMatter);
return `---\n${frontMatterString}\n---`;
});
return replaced;
Expand Down Expand Up @@ -279,7 +277,7 @@ export default class Publisher {

const headerSection = header ? `${header}\n` : '';

fileText = `\n<div class="transclusion">\n\n` + headerSection + fileText + '\n</div>\n'
fileText = `\n<div class="transclusion internal-embed is-loaded">\n\n` + headerSection + fileText + '\n</div>\n'
//This should be recursive up to a certain depth
transcludedText = transcludedText.replace(transclusionMatch, fileText);
}
Expand Down
4 changes: 2 additions & 2 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class DigitalGarden extends Plugin {
publishModal: PublishModal;

async onload() {
this.appVersion = "2.6.0";
this.appVersion = "2.6.1";

console.log("Initializing DigitalGarden plugin v" + this.appVersion);
await this.loadSettings();
Expand Down Expand Up @@ -219,7 +219,7 @@ class DigitalGardenSettingTab extends PluginSettingTab {

};
settingView.renderCreatePr(handlePR);
settingView.renderPullRequestHistory(this.plugin.settings.prHistory.slice(0,10));
settingView.renderPullRequestHistory(this.plugin.settings.prHistory.reverse().slice(0,10));
}
}

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "digitalgarden",
"name": "Digital Garden",
"version": "2.6.0",
"version": "2.6.1",
"minAppVersion": "0.12.0",
"description": "Publish your notes to a digital garden for others to enjoy.",
"author": "Ole Eskild Steensen",
Expand Down
1 change: 1 addition & 0 deletions versions.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"2.6.1": "0.12.0",
"2.6.0": "0.12.0",
"2.5.0": "0.12.0",
"2.4.0": "0.12.0",
Expand Down

0 comments on commit fdc4e24

Please sign in to comment.