mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-07-02 16:01:49 +02:00
Initial beta version release
This commit is contained in:
@@ -2,3 +2,4 @@ out
|
||||
node_modules
|
||||
.vscode-test/
|
||||
*.vsix
|
||||
.DS_Store
|
||||
+2
-6
@@ -1,9 +1,5 @@
|
||||
# Change Log
|
||||
|
||||
All notable changes to the "vscode-hugo-taxonomy" extension will be documented in this file.
|
||||
## [0.0.1] - 2019-08-26
|
||||
|
||||
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
- Initial release
|
||||
- Initial beta version
|
||||
@@ -1 +1,33 @@
|
||||
# VSCode Hugo Helpers
|
||||
# VSCode Front Matter Helpers
|
||||
|
||||
> **Info**: Extension is still in development, but can already be tested out.
|
||||
|
||||
## Available commands:
|
||||
|
||||
**Front Matter: Create <tag | category>**
|
||||
- Creates a new <tag | category> and allows you to automatically include it into your post
|
||||
|
||||

|
||||
|
||||
**Front Matter: Insert <tags | categories>**
|
||||
- Inserts a selected <tags | categories> into the front matter of your article/post/...
|
||||
|
||||

|
||||
|
||||
**Front Matter: Export all tags & categories to your settings**
|
||||
- Export all the already used tags & categories in your articles/posts/... to your user settings
|
||||
|
||||
## Where is the data stored?
|
||||
|
||||
The tags and categories are stored in the project VSCode user settings. You can find them back under: `.vscode/settings.json`.
|
||||
|
||||
```json
|
||||
{
|
||||
"frontMatter.taxonomy.tags": [],
|
||||
"frontMatter.taxonomy.categories": []
|
||||
}
|
||||
```
|
||||
|
||||
## Feedback / issues / ideas
|
||||
|
||||
Please submit them via creating an issue in the project repository: [issue list](https://github.com/estruyf/vscode-front-matter/issues).
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 202 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 232 KiB |
Generated
+1
-1
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "vscode-hugo-helpers",
|
||||
"name": "vscode-front-matter",
|
||||
"version": "0.0.1",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
|
||||
+36
-20
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "vscode-hugo-helpers",
|
||||
"displayName": "vscode-hugo-helpers",
|
||||
"description": "",
|
||||
"name": "vscode-front-matter",
|
||||
"displayName": "vscode-front-matter",
|
||||
"description": "Simplifies front matter configuration for your articles/posts/...",
|
||||
"version": "0.0.1",
|
||||
"publisher": "eliostruyf",
|
||||
"engines": {
|
||||
@@ -10,43 +10,59 @@
|
||||
"categories": [
|
||||
"Other"
|
||||
],
|
||||
"keywords": [
|
||||
"Front Matter",
|
||||
"Hugo",
|
||||
"Jekyll",
|
||||
"Taxonomy"
|
||||
],
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/estruyf/vscode-front-matter"
|
||||
},
|
||||
"activationEvents": [
|
||||
"onCommand:hugo.insertTags",
|
||||
"onCommand:hugo.insertCategories",
|
||||
"onCommand:hugo.createTag",
|
||||
"onCommand:hugo.createCategory"
|
||||
"onCommand:frontMatter.insertTags",
|
||||
"onCommand:frontMatter.insertCategories",
|
||||
"onCommand:frontMatter.createTag",
|
||||
"onCommand:frontMatter.createCategory",
|
||||
"onCommand:frontMatter.exportTaxonomy"
|
||||
],
|
||||
"main": "./out/extension.js",
|
||||
"contributes": {
|
||||
"configuration": {
|
||||
"title": "Hugo: Helpers Configuration",
|
||||
"title": "Front Matter: Configuration",
|
||||
"properties": {
|
||||
"hugo.taxonomy.tags": {
|
||||
"frontMatter.taxonomy.tags": {
|
||||
"type": "array",
|
||||
"description": "Specifies the tags which can be used for Hugo"
|
||||
"description": "Specifies the tags which can be used in the Front Matter"
|
||||
},
|
||||
"hugo.taxonomy.categories": {
|
||||
"frontMatter.taxonomy.categories": {
|
||||
"type": "array",
|
||||
"description": "Specifies the categories which can be used for Hugo"
|
||||
"description": "Specifies the categories which can be used in the Front Matter"
|
||||
}
|
||||
}
|
||||
},
|
||||
"commands": [
|
||||
{
|
||||
"command": "hugo.insertTags",
|
||||
"title": "Hugo: Insert tags"
|
||||
"command": "frontMatter.insertTags",
|
||||
"title": "Front Matter: Insert tags"
|
||||
},
|
||||
{
|
||||
"command": "hugo.insertCategories",
|
||||
"title": "Hugo: Insert categories"
|
||||
"command": "frontMatter.insertCategories",
|
||||
"title": "Front Matter: Insert categories"
|
||||
},
|
||||
{
|
||||
"command": "hugo.createTag",
|
||||
"title": "Hugo: Create tag"
|
||||
"command": "frontMatter.createTag",
|
||||
"title": "Front Matter: Create tag"
|
||||
},
|
||||
{
|
||||
"command": "hugo.createCategory",
|
||||
"title": "Hugo: Create category"
|
||||
"command": "frontMatter.createCategory",
|
||||
"title": "Front Matter: Create category"
|
||||
},
|
||||
{
|
||||
"command": "frontMatter.exportTaxonomy",
|
||||
"title": "Front Matter: Export all tags & categories to your settings"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
@@ -3,7 +3,7 @@ import { TaxonomyType } from "../models";
|
||||
import { CONFIG_KEY, ACTION_TAXONOMY_TAGS, ACTION_TAXONOMY_CATEGORIES } from "../constants/settings";
|
||||
import * as matter from "gray-matter";
|
||||
|
||||
export class Hugo {
|
||||
export class FrontMatter {
|
||||
|
||||
/**
|
||||
* Insert taxonomy
|
||||
@@ -125,6 +125,80 @@ export class Hugo {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Export the tags/categories front matter to the user settings
|
||||
*/
|
||||
public static async export() {
|
||||
const config = vscode.workspace.getConfiguration(CONFIG_KEY);
|
||||
|
||||
// Retrieve all the Markdown files
|
||||
const mdFiles = await vscode.workspace.findFiles('**/*.md', "**/node_modules/**");
|
||||
if (!mdFiles) {
|
||||
vscode.window.showInformationMessage(`No MD files found.`);
|
||||
return;
|
||||
}
|
||||
|
||||
vscode.window.withProgress({
|
||||
location: vscode.ProgressLocation.Notification,
|
||||
title: `Front Matter: exporting tags and categories`,
|
||||
cancellable: false
|
||||
}, async (progress) => {
|
||||
// Fetching all tags and categories from MD files
|
||||
let tags: string[] = [];
|
||||
let categories: string[] = [];
|
||||
|
||||
// Set the initial progress
|
||||
const progressNr = mdFiles.length/100;
|
||||
progress.report({ increment: 0});
|
||||
|
||||
let i = 0;
|
||||
for (const file of mdFiles) {
|
||||
progress.report({ increment: (++i/progressNr) });
|
||||
const mdFile = await vscode.workspace.openTextDocument(file);
|
||||
if (mdFile) {
|
||||
const txtData = mdFile.getText();
|
||||
if (txtData) {
|
||||
try {
|
||||
const article = matter(txtData);
|
||||
if (article && article.data) {
|
||||
const { data } = article;
|
||||
const mdTags = data["tags"];
|
||||
const mdCategories = data["categories"];
|
||||
if (mdTags) {
|
||||
tags = [...tags, ...mdTags];
|
||||
}
|
||||
if (mdCategories) {
|
||||
categories = [...categories, ...mdCategories];
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// Continue with the next file
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Retrieve the currently known tags, and add the new ones
|
||||
let crntTags: string[] = config.get(ACTION_TAXONOMY_TAGS) as string[];
|
||||
if (!crntTags) { crntTags = []; }
|
||||
crntTags = [...crntTags, ...tags];
|
||||
// Update the tags and filter out the duplicates
|
||||
crntTags = [...new Set(crntTags)];
|
||||
config.update(ACTION_TAXONOMY_TAGS, crntTags);
|
||||
|
||||
// Retrieve the currently known tags, and add the new ones
|
||||
let crntCategories: string[] = config.get(ACTION_TAXONOMY_CATEGORIES) as string[];
|
||||
if (!crntCategories) { crntCategories = []; }
|
||||
crntCategories = [...crntCategories, ...categories];
|
||||
// Update the categories and filter out the duplicates
|
||||
crntCategories = [...new Set(crntCategories)];
|
||||
config.update(ACTION_TAXONOMY_CATEGORIES, crntCategories);
|
||||
|
||||
// Done
|
||||
vscode.window.showInformationMessage(`Front Matter: export completed. Tags: ${crntTags.length} - Categories: ${crntCategories.length}.`);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the new information in the file
|
||||
*
|
||||
@@ -1 +1 @@
|
||||
export * from './Hugo';
|
||||
export * from './FrontMatter';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export const CONFIG_KEY = "hugo";
|
||||
export const CONFIG_KEY = "frontMatter";
|
||||
|
||||
export const ACTION_TAXONOMY_TAGS = "taxonomy.tags";
|
||||
export const ACTION_TAXONOMY_CATEGORIES = "taxonomy.categories";
|
||||
+13
-9
@@ -1,23 +1,27 @@
|
||||
import * as vscode from 'vscode';
|
||||
import { Hugo } from './commands';
|
||||
import { FrontMatter } from './commands';
|
||||
import { TaxonomyType } from './models';
|
||||
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
|
||||
let insertTags = vscode.commands.registerCommand('hugo.insertTags', () => {
|
||||
Hugo.insert(TaxonomyType.Tag);
|
||||
let insertTags = vscode.commands.registerCommand('frontMatter.insertTags', () => {
|
||||
FrontMatter.insert(TaxonomyType.Tag);
|
||||
});
|
||||
|
||||
let insertCategories = vscode.commands.registerCommand('hugo.insertCategories', () => {
|
||||
Hugo.insert(TaxonomyType.Category);
|
||||
let insertCategories = vscode.commands.registerCommand('frontMatter.insertCategories', () => {
|
||||
FrontMatter.insert(TaxonomyType.Category);
|
||||
});
|
||||
|
||||
let createTag = vscode.commands.registerCommand('hugo.createTag', () => {
|
||||
Hugo.create(TaxonomyType.Tag);
|
||||
let createTag = vscode.commands.registerCommand('frontMatter.createTag', () => {
|
||||
FrontMatter.create(TaxonomyType.Tag);
|
||||
});
|
||||
|
||||
let createCategory = vscode.commands.registerCommand('hugo.createCategory', () => {
|
||||
Hugo.create(TaxonomyType.Category);
|
||||
let createCategory = vscode.commands.registerCommand('frontMatter.createCategory', () => {
|
||||
FrontMatter.create(TaxonomyType.Category);
|
||||
});
|
||||
|
||||
let exportTaxonomy = vscode.commands.registerCommand('frontMatter.exportTaxonomy', () => {
|
||||
FrontMatter.export();
|
||||
});
|
||||
|
||||
context.subscriptions.push(insertTags);
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
export function firstToUpper(value: string) {
|
||||
return value.charAt(0).toUpperCase() + value.slice(1);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export * from './StringHelpers';
|
||||
Reference in New Issue
Block a user