Skip to content

Commit

Permalink
feat: allow dataPublished and dateSaved to be used as filename
Browse files Browse the repository at this point in the history
  • Loading branch information
sywhb committed Jun 19, 2023
1 parent f1f0a2d commit 22046e3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 26 deletions.
1 change: 0 additions & 1 deletion esbuild.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ esbuild.build({
'@lezer/common',
'@lezer/highlight',
'@lezer/lr',
'out-of-character',
...builtins],
format: 'cjs',
watch: !prod,
Expand Down
27 changes: 7 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ export default class OmnivorePlugin extends Plugin {
template,
folder,
filename,
folderDateFormat,
isSingleFile,
frontMatterVariables,
frontMatterTemplate,
Expand Down Expand Up @@ -254,7 +253,7 @@ export default class OmnivorePlugin extends Plugin {
);
// use the custom filename
const customFilename = replaceIllegalChars(
renderFilename(article, filename, folderDateFormat)
renderFilename(article, filename, this.settings.filenameDateFormat)
);
const pageName = `${folderName}/${customFilename}.md`;
const normalizedPath = normalizePath(pageName);
Expand Down Expand Up @@ -642,7 +641,7 @@ class OmnivoreSettingTab extends PluginSettingTab {
new Setting(containerEl)
.setName("Filename")
.setDesc(
"Enter the filename where the data will be stored. {{{title}}} and {{{date}}} could be used in the filename"
"Enter the filename where the data will be stored. {{{title}}}, {{{date}}} and {{{datePublished}}} could be used in the filename"
)
.addText((text) =>
text
Expand Down
9 changes: 7 additions & 2 deletions src/settings/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,17 @@ const functionMap: FunctionMap = {
export const renderFilename = (
article: Article,
filename: string,
folderDateFormat: string
dateFormat: string
) => {
const date = formatDate(article.savedAt, folderDateFormat);
const date = formatDate(article.savedAt, dateFormat);
const datePublished = article.publishedAt
? formatDate(article.publishedAt, dateFormat).trim()
: undefined;
const renderedFilename = Mustache.render(filename, {
...article,
date,
dateSaved: date,
datePublished,
});

// truncate the filename to 100 characters
Expand Down

0 comments on commit 22046e3

Please sign in to comment.