Skip to content

Commit

Permalink
feat: use another value than title to generate the filename
Browse files Browse the repository at this point in the history
See PR#29
  • Loading branch information
Mara-Li committed Sep 5, 2022
1 parent fe1617d commit c08a49b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
9 changes: 4 additions & 5 deletions plugin/contents_conversion/filePathConvertor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ function createFrontmatterPath(
settings: GitHubPublisherSettings,
frontmatter: FrontMatterCache,
fileName: string): string {
let path = settings.folderDefaultName.length > 0 ? settings.folderDefaultName + "/" + file.name : file.name;
let path = settings.folderDefaultName.length > 0 ? settings.folderDefaultName + "/" + fileName : fileName;
let folderRoot = settings.rootFolder;
if (folderRoot.length > 0) {
folderRoot = folderRoot + "/";
}
if (frontmatter && frontmatter[settings.yamlFolderKey]) {
const category = frontmatter[settings.yamlFolderKey]
const parentCatFolder = !category.endsWith('/') ? category.split('/').at(-1): category.split('/').at(-2);
fileName = settings.folderNote && parentCatFolder === file.name.replace('.md', '') ? 'index.md' : fileName
fileName = settings.folderNote && parentCatFolder === fileName.replace('.md', '') ? 'index.md' : fileName
path = folderRoot + frontmatter[settings.yamlFolderKey] + "/" + fileName;
}
return path
Expand All @@ -129,8 +129,8 @@ function createFrontmatterPath(
function getTitleField(frontmatter: FrontMatterCache, file: TFile, settings: GitHubPublisherSettings): string {
if (!settings.useFrontmatterTitle || !frontmatter) {
return file.name;
} else if (frontmatter && frontmatter['title'] && frontmatter['title'] !== file.name) {
return frontmatter['title'] + '.md';
} else if (frontmatter && frontmatter[settings.frontmatterTitleKey] && frontmatter[settings.frontmatterTitleKey] !== file.name) {
return frontmatter[settings.frontmatterTitleKey] + '.md';
}
return file.name;
}
Expand All @@ -155,7 +155,6 @@ function getReceiptFolder(
} else if (settings.downloadedFolder === folderSettings.obsidian) {
path = createObsidianPath(file, settings, vault, fileName);
}

return path
}
}
Expand Down
5 changes: 2 additions & 3 deletions plugin/i18n/locales/en-us.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export default {
frontmatterKeyPlaceholder: "category",
rootFolder: "Root folder",
rootFolderDesc: "Append this path to the folder set by the frontmatter key.",

useFrontmatterTitle: "Set the title from the frontmatter",
useFrontmatterTitleDesc: "Use a frontmatter value to generate the filename. By default, \"title\" is used.",
// ---
// # Text conversion # //
textConversion: "Content's conversion",
Expand All @@ -67,8 +68,6 @@ export default {
hardBreakDesc: "Add a markdown hard line break (double whitespace) after each line. This settings can be overridden by the frontmatter key \"hardbreak\".",
headerDataview: "Dataview",
headerDataviewDesc: "Convert dataview to markdown. This settings can be overridden by the frontmatter key \"dataview\".",
useFrontmatterTitle: "Use frontmatter title",
useFrontmatterTitleDesc: "Use frontmatter \"title\" field instead of the file name.",
censorTextHeader: "Text replacer",
censorTextDesc: "Replace text (or regex) in the file with the given value.",
censorTextInsensitive: "Case insensitive",
Expand Down
6 changes: 3 additions & 3 deletions plugin/i18n/locales/fr-fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ export default {
frontmatterKeyPlaceholder: "catégorie",
rootFolder: "Dossier racine",
rootFolderDesc: "Ajoutez ce chemin au dossier défini par la clé de métadonnées.",

useFrontmatterTitle: "Utiliser une clé de métadonnées pour le titre",
useFrontmatterTitleDesc: "Utilisez un champ du frontmatter pour générer le nom du fichier. Par défaut \"title\" est utilisé.",
// ---
// # Text conversions # //
textConversion: "Conversion du contenu",
Expand All @@ -68,8 +69,7 @@ export default {
hardBreakDesc: "Ajoutez un retour à la ligne Markdown (double espace) après chaque ligne. Ce paramètre peut être outrepassé par la clé de métadonnées \"hardbreak\".",
headerDataview: "Dataview",
headerDataviewDesc: "Convertir dataview en markdown. Ce paramètre peut être outrepassé par la clé de métadonnées \"dataview\".",
useFrontmatterTitle: "Utiliser la clé frontmatter \"title\"",
useFrontmatterTitleDesc: "Utilisez le champ \"title\" du frontmatter (à la place du nom du fichier) pour générer le chemin du fichier.",

censorTextHeader: "Replacement de texte",
censorTextDesc: "Replacement de texte (ou regex) par un autre texte.",
censorTextInsensitive: "Insensible à la casse.",
Expand Down
17 changes: 16 additions & 1 deletion plugin/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export class GithubPublisherSettings extends PluginSettingTab {
await this.plugin.saveSettings();
});
});
new Setting(this.containerEl)
const frontmatterTitleSet=new Setting(this.containerEl)
.setName(t('useFrontmatterTitle') as string)
.setDesc(t('useFrontmatterTitleDesc') as string)
.addToggle((toggle) => {
Expand All @@ -181,8 +181,23 @@ export class GithubPublisherSettings extends PluginSettingTab {
.onChange(async (value) => {
this.plugin.settings.useFrontmatterTitle = value;
await this.plugin.saveSettings();
this.display();
});
});
if (this.plugin.settings.useFrontmatterTitle) {
frontmatterTitleSet
.addText((text) => {
text
.setPlaceholder('title')
.setValue(this.plugin.settings.frontmatterTitleKey)
.onChange(async (value) => {
this.plugin.settings.frontmatterTitleKey = value.trim();
await this.plugin.saveSettings();
});
});
}


/* ------------------------------ *
* Text conversion *
* ------------------------------ */
Expand Down
2 changes: 2 additions & 0 deletions plugin/settings/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface GitHubPublisherSettings {
censorText: TextCleaner[];
inlineTags: boolean;
dataviewFields: string[];
frontmatterTitleKey: string;
excludeDataviewValue: string[];
metadataFileFields: string[];
}
Expand Down Expand Up @@ -79,6 +80,7 @@ export const DEFAULT_SETTINGS: GitHubPublisherSettings = {
dataviewFields: [],
excludeDataviewValue: [],
metadataFileFields:[],
frontmatterTitleKey: 'title',
}

export interface LinkedNotes {
Expand Down

0 comments on commit c08a49b

Please sign in to comment.