Skip to content

Commit

Permalink
feat(embed): allow to add text before /after embeds
Browse files Browse the repository at this point in the history
Future: change variable {{title}} and {{url}}
  • Loading branch information
Mara-Li committed Aug 23, 2023
1 parent abc0e32 commit 8d4cc45
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src/conversion/bakeEmbed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import {
resolveSubpath,
TFile} from "obsidian";

import {GitHubPublisherSettings, Repository} from "../settings/interface";
import {
GitHubPublisherSettings,
Repository
} from "../settings/interface";
import {isShared} from "../utils/data_validation_test";

/**
Expand Down Expand Up @@ -142,6 +145,9 @@ function extractSubpath(
* @param repo {Repository | null}
* @param settings {GitHubPublisherSettings} the global settings
* @param subpath {string|null} the subpath to extract, if any
* @param sourceRepo
* @param frontmatterSettings
* @param linkedNotes
* @return {string} the converted text
*/
export async function bakeEmbeds(
Expand Down
16 changes: 16 additions & 0 deletions src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,22 @@
"title": "Content's conversion"
},
"embed": {
"bake": {
"text": "Allow you to add text before and after each embed, for example adding HTML or stylize the block with markdown.",
"textAfter": {
"title": "Text after the block"
},
"textBefore": {
"title": "Text before the block"
},
"title": "Include embed settings",
"variable": {
"desc": "It is possible to use the following variable:",
"title": ": note embedded title",
"url": ": path to the embedded note"
},
"warning": "If you use HTML, depending of your host settings, the markdown will broke."
},
"char": {
"desc": "Character(s) to add before the link.",
"title": "Embed characters"
Expand Down
16 changes: 16 additions & 0 deletions src/i18n/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,22 @@
"title": "Conversion du contenu"
},
"embed": {
"bake": {
"text": "Permet d'ajouter du texte avant et après chaque intégration, par exemple en ajoutant du HTML ou en stylisant le bloc avec du markdown.",
"textAfter": {
"title": "Texte après le block"
},
"textBefore": {
"title": "Texte à ajouter avant le block"
},
"title": "Paramètres pour l'inclusion des embeds",
"variable": {
"desc": "Il est possible d'utiliser les variables suivantes :",
"title": " : Titre de la note inclue",
"url": " : Chemin vers la note inclue"
},
"warning": "Si vous utilisez du HTML, selon les paramètres de votre hébergeur, le Markdown sera cassé."
},
"char": {
"desc": "Caractère(s) à ajouter devant le lien.",
"title": "Caractère d'embed"
Expand Down
64 changes: 60 additions & 4 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ export class GithubPublisherSettingsTab extends PluginSettingTab {
/**
* Render the settings page for the embeds settings
*/
renderEmbedConfiguration() {
async renderEmbedConfiguration() {
this.settingsPage.empty();
const embedSettings = this.plugin.settings.embed;
new Setting(this.settingsPage)
Expand Down Expand Up @@ -817,7 +817,7 @@ export class GithubPublisherSettingsTab extends PluginSettingTab {
});
});

const embedNote = new Setting(this.settingsPage)
new Setting(this.settingsPage)
.setName(i18next.t("settings.embed.transferNotes.title"))
.setDesc(i18next.t("settings.embed.transferNotes.desc"))
.addToggle((toggle) => {
Expand All @@ -826,7 +826,7 @@ export class GithubPublisherSettingsTab extends PluginSettingTab {
.onChange(async (value) => {
embedSettings.notes = value;
await this.plugin.saveSettings();
this.renderEmbedConfiguration();
await this.renderEmbedConfiguration();
});
});

Expand All @@ -844,7 +844,7 @@ export class GithubPublisherSettingsTab extends PluginSettingTab {
.onChange(async (value) => {
embedSettings.convertEmbedToLinks = value as "keep" | "remove" | "links" | "bake";
await this.plugin.saveSettings();
this.renderEmbedConfiguration();
await this.renderEmbedConfiguration();
});
});

Expand All @@ -860,6 +860,62 @@ export class GithubPublisherSettingsTab extends PluginSettingTab {
await this.plugin.saveSettings();
});
});
} else if (embedSettings.convertEmbedToLinks === "bake") {
if (!embedSettings.bake) {
embedSettings.bake = {
textBefore: "",
textAfter: ""
};
await this.plugin.saveSettings();
}
await this.plugin.saveSettings();
this.settingsPage.createEl("h4", {text: i18next.t("settings.embed.bake.title")});
this.settingsPage.createEl("p", {text: i18next.t("settings.embed.bake.text")});
this.settingsPage.createEl("p", undefined, (el) => {
el.createEl("span", {
text: i18next.t("settings.embed.bake.variable.desc"),
cls: ["github-publisher", "bake"]
})
.createEl("ul", undefined, (ul) => {
ul.createEl("li", undefined, (li) => {
li.createEl("code", {text: "{{title}}"});
li.createEl("span", {text: i18next.t("settings.embed.bake.variable.title")});
});
ul.createEl("li", undefined, (li) => {
li.createEl("code", {text: "{{url}}"});
li.createEl("span", {text: i18next.t("settings.embed.bake.variable.url")});
});
});
});

this.settingsPage.createEl("p", {
text: `⚠️ ${i18next.t("settings.embed.bake.warning")}`,
cls: ["warning", "github-publisher", "embed"]
});

new Setting(this.settingsPage)
.setName(i18next.t("settings.embed.bake.textBefore.title"))
.setClass("github-publisher-textarea")
.addTextArea((text) => {
text
.setValue(embedSettings.bake?.textBefore ?? "")
.onChange(async (value) => {
embedSettings.bake!.textBefore = value;
await this.plugin.saveSettings();
});
});

new Setting(this.settingsPage)
.setName(i18next.t("settings.embed.bake.textAfter.title"))
.setClass("github-publisher-textarea")
.addTextArea((text) => {
text
.setValue(embedSettings.bake?.textAfter ?? "")
.onChange(async (value) => {
embedSettings.bake!.textAfter = value;
await this.plugin.saveSettings();
});
});
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,14 @@ h2.github-publisher.title.error {
color: var(--text-error);
font-weight: bold;
}

.github-publisher.warning.embed {
color: var(--color-orange);
font-weight: bold;
border-left: 3px solid var(--color-orange);
padding-left: 5px;
}

.github-publisher .bake ul {
margin-top: 0;
}

0 comments on commit 8d4cc45

Please sign in to comment.