Merge branch 'dev' of github.com:estruyf/vscode-front-matter into dev

This commit is contained in:
Elio Struyf
2021-12-21 11:13:34 +01:00
11 changed files with 107 additions and 46 deletions
+5
View File
@@ -8,6 +8,11 @@
- Optimized the `getMedia` call from the webview
- Keep the dashboard its context when switching tabs
- [#205](https://github.com/estruyf/vscode-front-matter/issues/205): Define a logging level setting
- [#206](https://github.com/estruyf/vscode-front-matter/issues/206): Add front matter issues to the diagnostic tab
### 🐞 Fixes
- [#207](https://github.com/estruyf/vscode-front-matter/issues/207): Fix the quick picks for content creation
## [5.7.0] - 2021-12-07 - [Release Notes](https://beta.frontmatter.codes/updates/v5.7.0)
+1 -1
View File
@@ -106,7 +106,7 @@ If you have the courage to test out the beta features, we made available a beta
</a>
</p>
## 🖤 Sponsors 👇 🤘
## 🖤 Backers & Sponsors 👇 🤘
<p align="center">
<a href="https://github.com/timschps" title="Tim Schaeps">
+1 -1
View File
@@ -104,7 +104,7 @@ If you have the courage to test out the beta features, we made available a beta
</a>
</p>
## 🖤 Sponsors 👇 🤘
## 🖤 Backers & Sponsors 👇 🤘
<p align="center">
<a href="https://github.com/timschps" title="Tim Schaeps">
+4
View File
@@ -11,6 +11,7 @@ import { Project } from './Project';
import { Folders } from './Folders';
import { ContentType } from '../helpers/ContentType';
import { ContentType as IContentType } from '../models';
import { PagesListener } from '../listeners';
export class Template {
@@ -176,6 +177,9 @@ export class Template {
}
Notifications.info(`Your new content has been created.`);
// Trigger a refresh for the dashboard
PagesListener.refresh();
}
/**
+28 -15
View File
@@ -1,3 +1,4 @@
import { MarkdownFoldingProvider } from './../providers/MarkdownFoldingProvider';
import { DEFAULT_CONTENT_TYPE, DEFAULT_CONTENT_TYPE_NAME } from './../constants/ContentType';
import * as vscode from 'vscode';
import * as matter from "gray-matter";
@@ -5,7 +6,7 @@ import * as fs from "fs";
import { DefaultFields, SETTING_COMMA_SEPARATED_FIELDS, SETTING_DATE_FIELD, SETTING_DATE_FORMAT, SETTING_INDENT_ARRAY, SETTING_REMOVE_QUOTES, SETTING_TAXONOMY_CONTENT_TYPES, SETTING_TEMPLATES_PREFIX } from '../constants';
import { DumpOptions } from 'js-yaml';
import { TomlEngine, getFmLanguage, getFormatOpts } from './TomlEngine';
import { Settings } from '.';
import { Extension, Settings } from '.';
import { format, parse } from 'date-fns';
import { Notifications } from './Notifications';
import { Article } from '../commands';
@@ -15,6 +16,7 @@ import sanitize from '../helpers/Sanitize';
import { existsSync, mkdirSync } from 'fs';
import { ContentType } from '../models';
import { DateHelper } from './DateHelper';
import { Diagnostic, DiagnosticSeverity, Position, window, Range } from 'vscode';
export class ArticleHelper {
private static notifiedFiles: string[] = [];
@@ -33,9 +35,9 @@ export class ArticleHelper {
* Retrieve the file's front matter by its path
* @param filePath
*/
public static getFrontMatterByPath(filePath: string, surpressNotification: boolean = false) {
public static getFrontMatterByPath(filePath: string) {
const file = fs.readFileSync(filePath, { encoding: "utf-8" });
return ArticleHelper.parseFile(file, filePath, surpressNotification);
return ArticleHelper.parseFile(file, filePath);
}
/**
@@ -226,7 +228,7 @@ export class ArticleHelper {
* @param fileContents
* @returns
*/
private static parseFile(fileContents: string, fileName: string, surpressNotification: boolean = false): matter.GrayMatterFile<string> | null {
private static parseFile(fileContents: string, fileName: string): matter.GrayMatterFile<string> | null {
try {
const commaSeparated = Settings.get<string[]>(SETTING_COMMA_SEPARATED_FIELDS);
@@ -249,6 +251,10 @@ export class ArticleHelper {
this.notifiedFiles = this.notifiedFiles.filter(n => n !== fileName);
if (window.activeTextEditor?.document.uri) {
Extension.getInstance().diagnosticCollection.delete(window.activeTextEditor.document.uri);
}
return article;
}
}
@@ -260,18 +266,25 @@ export class ArticleHelper {
}
}];
if (!surpressNotification) {
if (this.notifiedFiles.indexOf(fileName) === -1) {
Notifications.error(`There seems to be an issue parsing the content its front matter. FileName: ${basename(fileName)}. ERROR: ${error.message || error}`, ...items).then((result: any) => {
if (result?.title) {
const item = items.find(i => i.title === result.title);
if (item) {
item.action();
}
}
});
const editor = window.activeTextEditor;
if (editor?.document.uri) {
let fmRange = null;
this.notifiedFiles.push(fileName);
if (error?.mark && typeof error.mark.line !== "undefined") {
const curLineText = editor.document.lineAt(error.mark.line - 1);
const lastCharPos = new Position(error.mark.line - 1, Math.max(curLineText.text.length, 0));
fmRange = new Range(new Position(error.mark.line - 1, 0), lastCharPos);
} else {
fmRange = MarkdownFoldingProvider.getFrontMatterRange(editor.document);
}
if (fmRange) {
Extension.getInstance().diagnosticCollection.set(editor.document.uri, [{
severity: DiagnosticSeverity.Error,
message: `${error.name ? `${error.name}: ` : ""}Error parsing the front matter of ${fileName}`,
range: fmRange
}]);
}
}
}
+4
View File
@@ -1,3 +1,4 @@
import { PagesListener } from './../listeners/PagesListener';
import { ArticleHelper, Settings } from ".";
import { SETTINGS_CONTENT_DRAFT_FIELD, SETTING_TAXONOMY_CONTENT_TYPES } from "../constants";
import { ContentType as IContentType, DraftField } from '../models';
@@ -128,5 +129,8 @@ export class ContentType {
}
Notifications.info(`Your new content has been created.`);
// Trigger a refresh for the dashboard
PagesListener.refresh();
}
}
+1 -1
View File
@@ -67,7 +67,7 @@ export class CustomScript {
if (folder.lastModified.length > 0) {
for await (const file of folder.lastModified) {
try {
const article = ArticleHelper.getFrontMatterByPath(file.filePath, true);
const article = ArticleHelper.getFrontMatterByPath(file.filePath);
if (article) {
const crntOutput = await CustomScript.runScript(wsPath, article, file.filePath, script);
if (crntOutput) {
+9 -2
View File
@@ -1,6 +1,6 @@
import { existsSync, renameSync } from "fs";
import { basename, join } from "path";
import { extensions, Uri, ExtensionContext, window, workspace, commands, ExtensionMode } from "vscode";
import { extensions, Uri, ExtensionContext, window, workspace, commands, ExtensionMode, DiagnosticCollection, languages } from "vscode";
import { Folders, WORKSPACE_PLACEHOLDER } from "../commands/Folders";
import { EXTENSION_NAME, GITHUB_LINK, SETTINGS_CONTENT_FOLDERS, SETTINGS_CONTENT_PAGE_FOLDERS, SETTING_DATE_FIELD, SETTING_MODIFIED_FIELD, SETTING_SEO_DESCRIPTION_FIELD, SETTING_TAXONOMY_CONTENT_TYPES, DEFAULT_CONTENT_TYPE_NAME, EXTENSION_BETA_ID, EXTENSION_ID, ExtensionState, DefaultFields, LocalStore, SETTING_TEMPLATES_FOLDER } from "../constants";
import { ContentType } from "../models";
@@ -11,8 +11,11 @@ import { Settings } from "./SettingsHelper";
export class Extension {
private static instance: Extension;
private _collection: DiagnosticCollection;
private constructor(private ctx: ExtensionContext) {}
private constructor(private ctx: ExtensionContext) {
this._collection = languages.createDiagnosticCollection(this.title);
}
/**
* Creates the singleton instance for the panel
@@ -88,6 +91,10 @@ export class Extension {
return this.ctx.extensionMode === ExtensionMode.Production;
}
public get diagnosticCollection(): DiagnosticCollection {
return this._collection;
}
/**
* Set the current version information for the extension
*/
+2 -1
View File
@@ -45,7 +45,8 @@ export class Questions {
let selectedFolder: string | undefined;
if (folders.length > 1) {
selectedFolder = await window.showQuickPick(folders.map(f => f.title), {
placeHolder: `Select where you want to create your content`
placeHolder: `Select where you want to create your content`,
ignoreFocusOut: true
});
} else {
selectedFolder = folders[0].title;
+4
View File
@@ -124,4 +124,8 @@ export class PagesListener extends BaseListener {
this.sendMsg(DashboardCommand.pages, pages);
}
public static refresh() {
this.getPagesData();
}
}
+48 -25
View File
@@ -13,31 +13,15 @@ export class MarkdownFoldingProvider implements FoldingRangeProvider {
public async provideFoldingRanges(document: TextDocument, context: FoldingContext, token: CancellationToken): Promise<FoldingRange[]> {
const ranges: FoldingRange[] = [];
const lines = document.getText().split('\n');
let start: number | null = null;
let end: number | null = null;
const range = MarkdownFoldingProvider.getFrontMatterRange(document);
if (range) {
MarkdownFoldingProvider.start = null;
MarkdownFoldingProvider.end = null;
MarkdownFoldingProvider.endLine = null;
MarkdownFoldingProvider.start = null;
MarkdownFoldingProvider.end = null;
MarkdownFoldingProvider.endLine = null;
MarkdownFoldingProvider.triggerHighlighting();
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
if (line.startsWith('---')) {
if (i === 0 && start === null) {
start = i;
MarkdownFoldingProvider.start = start;
} else if (start !== null && end === null) {
end = i;
MarkdownFoldingProvider.end = end;
MarkdownFoldingProvider.endLine = line.length;
MarkdownFoldingProvider.triggerHighlighting();
ranges.push(new FoldingRange(start, end, FoldingRangeKind.Region));
return ranges;
}
}
ranges.push(new FoldingRange(range.start.line, range.end.line, FoldingRangeKind.Region));
}
return ranges;
@@ -46,9 +30,9 @@ export class MarkdownFoldingProvider implements FoldingRangeProvider {
public static triggerHighlighting() {
const fmHighlight = Settings.get<boolean>(SETTINGS_CONTENT_FRONTMATTER_HIGHLIGHT);
if (MarkdownFoldingProvider.start !== null && MarkdownFoldingProvider.end !== null && MarkdownFoldingProvider.endLine !== null) {
const range = new Range(new Position(MarkdownFoldingProvider.start, 0), new Position(MarkdownFoldingProvider.end, MarkdownFoldingProvider.endLine));
const range = this.getFrontMatterRange();
if (range) {
if (MarkdownFoldingProvider.decType !== null) {
MarkdownFoldingProvider.decType.dispose();
}
@@ -59,4 +43,43 @@ export class MarkdownFoldingProvider implements FoldingRangeProvider {
}
}
}
/**
* Retrieve the range of the current Front Matter page
* @param document
* @returns
*/
public static getFrontMatterRange(document?: TextDocument) {
if (document) {
const lines = document.getText().split('\n');
let start = null;
let end = null;
let endLine = null;
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
if (line.startsWith('---')) {
if (i === 0 && start === null) {
start = i;
} else if (start !== null && end === null) {
end = i;
endLine = line.length;
MarkdownFoldingProvider.triggerHighlighting();
return new Range(new Position(start, 0), new Position(end, endLine));
}
}
}
}
if (MarkdownFoldingProvider.start !== null && MarkdownFoldingProvider.end !== null && MarkdownFoldingProvider.endLine !== null) {
const range = new Range(new Position(MarkdownFoldingProvider.start, 0), new Position(MarkdownFoldingProvider.end, MarkdownFoldingProvider.endLine));
return range;
}
return null;
}
}