mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-05-18 07:15:43 +02:00
Added set lastmod date command
This commit is contained in:
+5
-1
@@ -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
|
||||
- Initial beta version
|
||||
|
||||
@@ -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).
|
||||
Please submit them via creating an issue in the project repository: [issue list](https://github.com/estruyf/vscode-front-matter/issues).
|
||||
|
||||
+6
-1
@@ -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"
|
||||
|
||||
+44
-14
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-2
@@ -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);
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user