diff --git a/CHANGELOG.md b/CHANGELOG.md index fc04ada7..62ac274b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## [1.4.0] - 2020-08-24 + +- Added set lastmod date command + ## [1.3.0] - 2020-08-22 - Added SEO description warning when over 140 characters is used @@ -61,4 +65,4 @@ ## [0.0.1] - 2019-08-26 -- Initial beta version \ No newline at end of file +- Initial beta version diff --git a/README.md b/README.md index 2be12568..f79ecdc4 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,12 @@ Update the `date` property of the current article/post/... to the current date & **Optional**: if you want, you can specify the date property format by adding your preference in your settings. Settings key: `frontMatter.taxonomy.dateFormat`. Check [date-fns formatting](https://date-fns.org/v2.0.1/docs/format) for more information on which patterns you can use. +**Front Matter: Set lastmod date** + +Update the `lastmod` (last modified) property of the current article/post/... to the current date & time. + +**note**: Uses the same date format settings key as current date: `frontMatter.taxonomy.dateFormat`. + **Front Matter: Generate slug based on article title** This command generates a clean slug for your article. It removes known stop words, punctuations, and special characters. @@ -105,4 +111,4 @@ The extension has more settings that allow you to configure it to your needs fur ## Feedback / issues / ideas -Please submit them via creating an issue in the project repository: [issue list](https://github.com/estruyf/vscode-front-matter/issues). \ No newline at end of file +Please submit them via creating an issue in the project repository: [issue list](https://github.com/estruyf/vscode-front-matter/issues). diff --git a/package.json b/package.json index 36c138ea..0ce3c36b 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "displayName": "Front Matter", "description": "Simplifies working with front matter of your articles. Useful extension when you are using a static site generator like: Hugo, Jekyll, Hexo, NextJs, Gatsby, and many more...", "icon": "assets/front-matter.png", - "version": "1.3.0", + "version": "1.4.0", "preview": false, "publisher": "eliostruyf", "galleryBanner": { @@ -45,6 +45,7 @@ "onCommand:frontMatter.exportTaxonomy", "onCommand:frontMatter.remap", "onCommand:frontMatter.setDate", + "onCommand:frontMatter.setLastModifiedDate", "onCommand:frontMatter.generateSlug" ], "main": "./dist/extension", @@ -125,6 +126,10 @@ "command": "frontMatter.setDate", "title": "Front Matter: Set current date" }, + { + "command": "frontMatter.setLastModifiedDate", + "title": "Front Matter: Set lastmod date" + }, { "command": "frontMatter.generateSlug", "title": "Front Matter: Generate slug based on article title" diff --git a/src/commands/Article.ts b/src/commands/Article.ts index b142ae48..3fa0ae88 100644 --- a/src/commands/Article.ts +++ b/src/commands/Article.ts @@ -9,8 +9,8 @@ export class Article { /** * Insert taxonomy - * - * @param type + * + * @param type */ public static async insert(type: TaxonomyType) { const config = vscode.workspace.getConfiguration(CONFIG_KEY); @@ -18,15 +18,15 @@ export class Article { if (!editor) { return; } - + const article = ArticleHelper.getFrontMatter(editor); if (!article) { return; } - + let options: vscode.QuickPickItem[] = []; const matterProp: string = type === TaxonomyType.Tag ? "tags" : "categories"; - + // Add the selected options to the options array if (article.data[matterProp]) { const propData = article.data[matterProp]; @@ -37,7 +37,7 @@ export class Article { } as vscode.QuickPickItem)); } } - + // Add all the known options to the selection list const crntOptions = SettingsHelper.getTaxonomy(type); if (crntOptions && crntOptions.length > 0) { @@ -49,21 +49,21 @@ export class Article { } } } - + if (options.length === 0) { vscode.window.showInformationMessage(`${EXTENSION_NAME}: No ${type === TaxonomyType.Tag ? "tags" : "categories"} configured.`); return; } - - const selectedOptions = await vscode.window.showQuickPick(options, { + + const selectedOptions = await vscode.window.showQuickPick(options, { placeHolder: `Select your ${type === TaxonomyType.Tag ? "tags" : "categories"} to insert`, - canPickMany: true + canPickMany: true }); - + if (selectedOptions) { article.data[matterProp] = selectedOptions.map(o => o.label); } - + ArticleHelper.update(editor, article); } @@ -89,7 +89,37 @@ export class Article { } else { article.data["date"] = new Date(); } - + + ArticleHelper.update(editor, article); + } catch (e) { + vscode.window.showErrorMessage(`${EXTENSION_NAME}: Something failed while parsing the date format. Check your "${CONFIG_KEY}${SETTING_DATE_FORMAT}" setting.`); + console.log(e.message); + } + } + + /** + * Sets the article lastmod date + */ + public static async setLastModifiedDate() { + const config = vscode.workspace.getConfiguration(CONFIG_KEY); + const editor = vscode.window.activeTextEditor; + if (!editor) { + return; + } + + const article = ArticleHelper.getFrontMatter(editor); + if (!article) { + return; + } + + const dateFormat = config.get(SETTING_DATE_FORMAT) as string; + try { + if (dateFormat && typeof dateFormat === "string") { + article.data["lastmod"] = format(new Date(), dateFormat); + } else { + article.data["lastmod"] = new Date(); + } + ArticleHelper.update(editor, article); } catch (e) { vscode.window.showErrorMessage(`${EXTENSION_NAME}: Something failed while parsing the date format. Check your "${CONFIG_KEY}${SETTING_DATE_FORMAT}" setting.`); @@ -139,4 +169,4 @@ export class Article { article.data["draft"] = newDraftStatus; ArticleHelper.update(editor, article); } -} \ No newline at end of file +} diff --git a/src/extension.ts b/src/extension.ts index 33323bd8..ea841de0 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -32,11 +32,15 @@ export function activate({ subscriptions }: vscode.ExtensionContext) { let remap = vscode.commands.registerCommand('frontMatter.remap', () => { Settings.remap(); }); - + let setDate = vscode.commands.registerCommand('frontMatter.setDate', () => { Article.setDate(); }); + let setLastModifiedDate = vscode.commands.registerCommand('frontMatter.setLastModifiedDate', () => { + Article.setLastModifiedDate(); + }); + let generateSlug = vscode.commands.registerCommand('frontMatter.generateSlug', () => { Article.generateSlug(); }); @@ -66,6 +70,7 @@ export function activate({ subscriptions }: vscode.ExtensionContext) { subscriptions.push(exportTaxonomy); subscriptions.push(remap); subscriptions.push(setDate); + subscriptions.push(setLastModifiedDate); subscriptions.push(generateSlug); subscriptions.push(toggleDraft); } @@ -84,4 +89,4 @@ const debounceShowDraftTrigger = () => { clearTimeout(timeout); timeout = setTimeout(functionCall, time); }; -}; \ No newline at end of file +};