mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-03-28 17:42:40 +01:00
Merge branch 'issue/65' into main
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
# Change Log
|
||||
|
||||
## [2.6.0]
|
||||
## [3.0.0]
|
||||
|
||||
- [#61](https://github.com/estruyf/vscode-front-matter/issues/61): List of recently modified files
|
||||
- [#64](https://github.com/estruyf/vscode-front-matter/issues/64): Publish toggle for easier publishing an article
|
||||
- [#65](https://github.com/estruyf/vscode-front-matter/issues/65): Aggregate articles in draft
|
||||
- [#66](https://github.com/estruyf/vscode-front-matter/issues/66): New dashboard webview on which you can manage all your content
|
||||
|
||||
## [2.5.1] - 2020-08-23
|
||||
|
||||
|
||||
95
README.md
95
README.md
@@ -20,9 +20,17 @@
|
||||
</a>
|
||||
</p>
|
||||
|
||||
This VSCode extension simplifies working with your markdown articles' front matter when using a static site generator like Hugo, Jekyll, Hexo, NextJs, Gatsby, and many more... For example, you can keep a list of used tags, categories and add/remove them from your article with the extension.
|
||||
Front Matter is an essential Visual Studio Code extension that simplifies working and managing your markdown articles. We created the extension to support many static-site generators like Hugo, Jekyll, Hexo, NextJs, Gatsby, and more.
|
||||
|
||||
The extension will automatically verify if your title and description are SEO compliant. If this would not be the case, it will give you a warning.
|
||||
The extension brings Content Management System (CMS) capabilities straight within Visual Studio Code. For example, you can keep a list of the used tags, categories, create content, and so much more.
|
||||
|
||||
Our main extension features are:
|
||||
|
||||
- Page dashboard where you can get an overview of all your markdown pages. You can use it to search, filter, sort your contents.
|
||||
- Site preview within Visual Studio Code
|
||||
- SEO checks for title, description, and keywords
|
||||
- Support for custom actions/scripts
|
||||
- and many more
|
||||
|
||||
<p align="center">
|
||||
<img src="./assets/v2.5.0/site-preview.png" alt="Site preview" style="display: inline-block" />
|
||||
@@ -30,9 +38,13 @@ The extension will automatically verify if your title and description are SEO co
|
||||
|
||||
> If you see something missing in your article creation flow, please feel free to reach out.
|
||||
|
||||
**Version 3**
|
||||
|
||||
In version v3 we introduced the dashboard webview. Which allows you to manage all your markdown pages in one place. This makes it easy to search, filter, sort, and more.
|
||||
|
||||
**Version 2**
|
||||
|
||||
In version v2.0.0 we released the newly redesigned sidebar panel with improved SEO support. This extension makes it the only extension to manage your Markdown pages for your static sites in Visual Studio Code.
|
||||
In version v2 we released the re-designed sidebar panel with improved SEO support. This extension makes it the only extension to manage your Markdown pages for your static sites in Visual Studio Code.
|
||||
|
||||
<p align="center" style="margin-top: 2rem;">
|
||||
<a href="https://www.producthunt.com/posts/front-matter?utm_source=badge-featured&utm_medium=badge&utm_souce=badge-front-matter" target="_blank">
|
||||
@@ -46,6 +58,7 @@ In version v2.0.0 we released the newly redesigned sidebar panel with improved S
|
||||
<summary>Table of Contents</summary>
|
||||
<ol>
|
||||
<li><a href="#markdown-features">Markdown features</a></li>
|
||||
<li><a href="#dashboard">Dashboard</a></li>
|
||||
<li><a href="#the-panel">The panel</a></li>
|
||||
<li><a href="#site-preview">Site preview</a></li>
|
||||
<li><a href="#custom-actions">Custom actions/scripts</a></li>
|
||||
@@ -75,6 +88,24 @@ The Front Matter extension tries to make it easy to manage your Markdown pages/c
|
||||
|
||||
> **Info**: If you do not want this feature, you can disable it in the extension settings -> `Highlight Front Matter` or by setting the `frontMatter.content.fmHighlight` setting to `false`.
|
||||
|
||||
## Dashboard
|
||||
|
||||
Managing your Markdown pages has never been easier in VS Code. With the Front Matter dashboard, you will be able to view all your pages and search through them, filter, sort, and much more.
|
||||
|
||||
<p align="center">
|
||||
<img src="./assets/v3.0.0/dashboard.png" alt="Dashboard" style="display: inline-block" />
|
||||
</p>
|
||||
|
||||
In order to start using the dashboard, you will have to let the extension know in which folder(s) it can find your pages. A content folder can be registered or unregistered, by right-clicking on the folder in your VSCode explorer panel and clicking on the `Register folder` or `Unregister folder` menu item.
|
||||
|
||||
<p align="center">
|
||||
<img src="./assets/v2.1.0/register-folder.png" alt="Register/unregister a folder" style="display: inline-block" />
|
||||
</p>
|
||||
|
||||
> **Info**: If you want, you can click on the `Open on startup?` checkbox. This setting will allow the dashboard to automatically open when you launch the project in VS Code. It will only apply to the current project, not for all of them.
|
||||
|
||||
> **Details**: If your preview images aren't loaded, it might be that you need to configure the `publicFolder` where the extension can find them. For instance, in Hugo this is the `static` folder. You can configure this by updating the `frontMatter.content.publicFolder` setting.
|
||||
|
||||
## The panel
|
||||
|
||||
The Front Matter panel allows you to perform most of the extension actions by just a click on the button and it shows the SEO statuses of your title, description, and more.
|
||||
@@ -86,7 +117,7 @@ To leverage most of the capabilities of the extension. SEO information and every
|
||||
When you open the panel and the current file is not a Markdown file, it will contain the following sections:
|
||||
|
||||
<p align="center">
|
||||
<img src="./assets/v2.5.0/baseview.png" alt="Base view" style="display: inline-block" />
|
||||
<img src="./assets/v3.0.0/baseview.png" alt="Base view" style="display: inline-block" />
|
||||
</p>
|
||||
|
||||
> **Info**: both **Global Settings** and **Other Actions** sections are shown for the base view as when a Markdown file is openend.
|
||||
@@ -113,14 +144,22 @@ When you open the Front Matter panel on a Markdown file, you get to see the foll
|
||||
|
||||
> **Info**: To gain the `open preview` button to show up, you will need to first set the `local preview URL`. You can do this within the `Global Settings` section or by updating the `frontMatter.preview.host` setting.
|
||||
|
||||
**Metadata: Keywords, Tags, Categories**
|
||||
**Metadata**
|
||||
|
||||
<p align="center">
|
||||
<img src="./assets/v2.0.0/metadata.png" alt="Article metadata" style="display: inline-block" />
|
||||
<img src="./assets/v3.0.0/metadata.png" alt="Article metadata" style="display: inline-block" />
|
||||
</p>
|
||||
|
||||
> **Info**: By default, the tags/categories picker allows you to insert existing and none tags/categories. When you enter a none existing tag/category, the panel shows an add `+` icon in front of that button. This functionality allows you to store this tag/category in your settings. If you want to disable this feature, you can do that by setting the `frontMatter.panel.freeform` setting to `false`.
|
||||
|
||||
**Recently Modified**
|
||||
|
||||
<p align="center">
|
||||
<img src="./assets/v3.0.0/recent-files.png" alt="Recently modified files" style="display: inline-block" />
|
||||
</p>
|
||||
|
||||
Navigate quickly to a recently modified file. In the section, the latest 10 modified files get shown. In order to use this functionality, a registered content folder needs to be present. Check [Front Matter: New article from template](#front-matter-new-article-from-template) for more information about how you can register your content folders.
|
||||
|
||||
**Other actions**
|
||||
|
||||
<p align="center">
|
||||
@@ -191,17 +230,17 @@ When adding files in the folder, you'll be able to run the `Front Matter: New ar
|
||||
|
||||
## Available commands
|
||||
|
||||
**Front Matter: Initialize project**
|
||||
### Front Matter: Initialize project
|
||||
|
||||
This command will initialize the project with a template folder and an article template. It makes it easier to get you started with the extension and creating your content.
|
||||
|
||||
**Front Matter: Create a template from current file**
|
||||
### Front Matter: Create a template from current file
|
||||
|
||||
This command allows you to create a new template from the current open Markdown file. It will ask you for the name of the template and if you want to keep the current file its content in the template.
|
||||
|
||||
> **Info**: The create as template action is also available from the `other actions` section in the Front Matter panel.
|
||||
|
||||
**Front Matter: New article from template**
|
||||
### Front Matter: New article from template
|
||||
|
||||
With this command, you can easily create content in your project within the registered folders and provided templates.
|
||||
|
||||
@@ -215,7 +254,7 @@ Once you registered a folder and a template has been defined ([how to create a t
|
||||
|
||||
> **Info**: The benefit of this command is that you do not need to search the folder in which you want to create a new article/page/... The extension will do it automatically for you.
|
||||
|
||||
**Front Matter: Create <tag | category>**
|
||||
### Front Matter: Create <tag | category>
|
||||
|
||||
Creates a new <tag | category> and allows you to include it into your post automatically
|
||||
|
||||
@@ -223,35 +262,35 @@ Creates a new <tag | category> and allows you to include it into your post autom
|
||||
<img src="./assets/create-tag-category.gif" alt="Create tag or category" style="display: inline-block" />
|
||||
</p>
|
||||
|
||||
**Front Matter: Insert <tags | categories>**
|
||||
### Front Matter: Insert <tags | categories>
|
||||
|
||||
Inserts a selected <tags | categories> into the front matter of your article/post/... - When using this command, the Front Matter panel opens and focuses on the specified type.
|
||||
|
||||
> **Info**: This experience changed in version `1.11.0`.
|
||||
|
||||
**Front Matter: Export all tags & categories to your settings**
|
||||
### Front Matter: Export all tags & categories to your settings
|
||||
|
||||
Export all the already used tags & categories in your articles/posts/... to your user settings.
|
||||
|
||||
**Front Matter: Remap or remove tag/category in all articles**
|
||||
### Front Matter: Remap or remove tag/category in all articles
|
||||
|
||||
This command helps you quickly update/remap or delete a tag or category in your markdown files. The extension will ask you to select the taxonomy type (*tag* or *category*), the old taxonomy value, and the new one (leave the input field *blank* to remove the tag/category).
|
||||
|
||||
> **Info**: Once the remapping/deleting process completes. Your VSCode settings update with all new taxonomy tags/categories.
|
||||
|
||||
**Front Matter: Set current date**
|
||||
### Front Matter: Set current date
|
||||
|
||||
Update the `date` property of the current article/post/... to the current date & time.
|
||||
|
||||
**Optional**: if you want, you can specify the date property format by adding your settings' preference. 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.
|
||||
> **Optional**: if you want, you can specify the date property format by adding your settings' preference. 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**
|
||||
### Front Matter: Set lastmod date
|
||||
|
||||
Update the `lastmod` (last modified) property of the current article/post/... to the current date & time. By setting the `frontMatter.content.autoUpdateDate` setting, it can be done automatically when performing changes to your markdown files.
|
||||
|
||||
> **note**: Uses the same date format settings key as current date: `frontMatter.taxonomy.dateFormat`.
|
||||
|
||||
**Front Matter: Generate slug based on article title**
|
||||
### 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.
|
||||
|
||||
@@ -266,7 +305,7 @@ You can also specify a prefix and suffix, which can be added to the slug if you
|
||||
|
||||
> **Info**: At the moment, the extension only supports English stopwords.
|
||||
|
||||
**Front Matter: Preview article**
|
||||
### Front Matter: Preview article
|
||||
|
||||
Opens the site preview for the current article. More information about it can be found in the [site preview](#site-preview) section.
|
||||
|
||||
@@ -455,6 +494,26 @@ Specify the path you want to add after the host and before your slug. This can b
|
||||
|
||||
> **Important**: As the value will be formatted with the article's date, it will try to convert all characters you enter. In case you wan to skip some characters or all of them, you need to wrap that part between two single quotes. Example: `"'blog/'yyyy/MM"` will result in: `blog/2021/08`.
|
||||
|
||||
### `frontMatter.dashboard.openOnStart`
|
||||
|
||||
Specify if you want to open the dashboard when you start VS Code.
|
||||
|
||||
```json
|
||||
{
|
||||
"frontMatter.dashboard.openOnStart": null
|
||||
}
|
||||
```
|
||||
|
||||
### `frontMatter.content.publicFolder`
|
||||
|
||||
Specify the folder name where all your assets are located. For instance in Hugo this is the `static` folder.
|
||||
|
||||
```json
|
||||
{
|
||||
"frontMatter.content.publicFolder": ""
|
||||
}
|
||||
```
|
||||
|
||||
## Feedback / issues / ideas
|
||||
|
||||
Please submit them via creating an issue in the project repository: [issue list](https://github.com/estruyf/vscode-front-matter/issues).
|
||||
|
||||
@@ -470,4 +470,40 @@ input:checked + .field__toggle__slider:before {
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
/* Sponsor */
|
||||
.sponsor {
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.sponsor:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.sponsor:hover svg {
|
||||
fill: currentcolor;
|
||||
}
|
||||
|
||||
.sponsor svg {
|
||||
height: 20px;
|
||||
width: 20px;
|
||||
margin-right: .25rem;
|
||||
}
|
||||
|
||||
.sponsor a {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: var(--vscode-foreground);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.sponsor a:hover {
|
||||
color: var(--vscode-foreground);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.sponsor a > span {
|
||||
margin-right: .25rem;
|
||||
}
|
||||
BIN
assets/v3.0.0/baseview.png
Normal file
BIN
assets/v3.0.0/baseview.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 99 KiB |
BIN
assets/v3.0.0/dashboard.png
Normal file
BIN
assets/v3.0.0/dashboard.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 326 KiB |
BIN
assets/v3.0.0/metadata.png
Normal file
BIN
assets/v3.0.0/metadata.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 29 KiB |
BIN
assets/v3.0.0/recent-files.png
Normal file
BIN
assets/v3.0.0/recent-files.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 39 KiB |
1078
package-lock.json
generated
1078
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
29
package.json
29
package.json
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "vscode-front-matter",
|
||||
"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...",
|
||||
"description": "An essential Visual Studio Code extension when you want to manage the markdown pages of your static site like: Hugo, Jekyll, Hexo, NextJs, Gatsby, and many more...",
|
||||
"icon": "assets/frontmatter-128x128.png",
|
||||
"version": "2.5.1",
|
||||
"preview": false,
|
||||
@@ -59,6 +59,7 @@
|
||||
"onCommand:frontMatter.init",
|
||||
"onCommand:frontMatter.collapseSections",
|
||||
"onCommand:frontMatter.preview",
|
||||
"onCommand:frontMatter.dashboard",
|
||||
"onView:frontMatter.explorer"
|
||||
],
|
||||
"main": "./dist/extension",
|
||||
@@ -101,11 +102,21 @@
|
||||
"default": [],
|
||||
"markdownDescription": "This array of folders defines where the extension can easily create new content by running the create article command."
|
||||
},
|
||||
"frontMatter.content.publicFolder": {
|
||||
"type": "string",
|
||||
"default": "",
|
||||
"markdownDescription": "Specify the folder name where all your assets are located. For instance in Hugo this is the `static` folder."
|
||||
},
|
||||
"frontMatter.custom.scripts": {
|
||||
"type": "array",
|
||||
"default": [],
|
||||
"markdownDescription": "Specify the path to a Node.js script to execute. The current file path will be provided as an argument."
|
||||
},
|
||||
"frontMatter.dashboard.openOnStart": {
|
||||
"type": "boolean",
|
||||
"default": null,
|
||||
"description": "Specify if you want to open the dashboard when you start VS Code."
|
||||
},
|
||||
"frontMatter.panel.freeform": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
@@ -299,6 +310,11 @@
|
||||
"command": "frontMatter.preview",
|
||||
"title": "Preview article",
|
||||
"category": "Front matter"
|
||||
},
|
||||
{
|
||||
"command": "frontMatter.dashboard",
|
||||
"title": "Open pages dashboard",
|
||||
"category": "Front matter"
|
||||
}
|
||||
],
|
||||
"menus": {
|
||||
@@ -373,15 +389,22 @@
|
||||
"@types/react-dom": "17.0.0",
|
||||
"@types/vscode": "1.51.0",
|
||||
"@vscode/codicons": "0.0.20",
|
||||
"date-fns": "2.0.1",
|
||||
"autoprefixer": "^10.3.2",
|
||||
"css-loader": "5.2.7",
|
||||
"date-fns": "2.23.0",
|
||||
"downshift": "6.0.6",
|
||||
"fuse.js": "6.4.6",
|
||||
"glob": "7.1.6",
|
||||
"gray-matter": "4.0.2",
|
||||
"html-loader": "1.3.2",
|
||||
"html-webpack-plugin": "4.5.0",
|
||||
"mdast-util-from-markdown": "1.0.0",
|
||||
"postcss": "^8.3.6",
|
||||
"postcss-loader": "4.3.0",
|
||||
"react": "17.0.1",
|
||||
"react-dom": "17.0.1",
|
||||
"style-loader": "2.0.0",
|
||||
"tailwindcss": "^2.2.7",
|
||||
"ts-loader": "8.0.3",
|
||||
"tslint": "6.1.3",
|
||||
"typescript": "4.0.2",
|
||||
@@ -390,6 +413,8 @@
|
||||
"webpack-cli": "3.3.12"
|
||||
},
|
||||
"dependencies": {
|
||||
"@headlessui/react": "1.4.0",
|
||||
"@heroicons/react": "1.0.4",
|
||||
"lodash.uniqby": "4.7.0"
|
||||
}
|
||||
}
|
||||
|
||||
8
postcss.config.js
Normal file
8
postcss.config.js
Normal file
@@ -0,0 +1,8 @@
|
||||
const tailwindcss = require('tailwindcss');
|
||||
|
||||
module.exports = {
|
||||
plugins: [
|
||||
tailwindcss('./tailwind.config.js'),
|
||||
require('autoprefixer'),
|
||||
],
|
||||
};
|
||||
235
src/commands/Dashboard.ts
Normal file
235
src/commands/Dashboard.ts
Normal file
@@ -0,0 +1,235 @@
|
||||
import { SETTINGS_CONTENT_STATIC_FOLDERS, SETTING_DATE_FIELD, SETTING_SEO_DESCRIPTION_FIELD, SETTINGS_DASHBOARD_OPENONSTART } from './../constants/settings';
|
||||
import { ArticleHelper } from './../helpers/ArticleHelper';
|
||||
import { join } from "path";
|
||||
import { commands, Uri, ViewColumn, Webview, WebviewPanel, window, workspace } from "vscode";
|
||||
import { SettingsHelper } from '../helpers';
|
||||
import { TaxonomyType } from '../models';
|
||||
import { Folders } from './Folders';
|
||||
import { getNonce } from '../helpers/getNonce';
|
||||
import { DashboardCommand } from '../pagesView/DashboardCommand';
|
||||
import { DashboardMessage } from '../pagesView/DashboardMessage';
|
||||
import { Page } from '../pagesView/models/Page';
|
||||
import { openFileInEditor } from '../helpers/openFileInEditor';
|
||||
import { COMMAND_NAME } from '../constants/Extension';
|
||||
import { Template } from './Template';
|
||||
import { Notifications } from '../helpers/Notifications';
|
||||
import { Settings } from '../pagesView/models/Settings';
|
||||
|
||||
|
||||
export class Dashboard {
|
||||
private static webview: WebviewPanel | null = null;
|
||||
private static isDisposed: boolean = true;
|
||||
|
||||
/**
|
||||
* Init the dashboard
|
||||
*/
|
||||
public static async init(extensionPath: string) {
|
||||
const config = SettingsHelper.getConfig();
|
||||
const openOnStartup = config.get(SETTINGS_DASHBOARD_OPENONSTART);
|
||||
if (openOnStartup) {
|
||||
Dashboard.open(extensionPath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Open or reveal the dashboard
|
||||
*/
|
||||
public static async open(extensionPath: string) {
|
||||
if (Dashboard.isOpen) {
|
||||
Dashboard.reveal();
|
||||
} else {
|
||||
Dashboard.create(extensionPath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the dashboard is still open
|
||||
*/
|
||||
public static get isOpen(): boolean {
|
||||
return !Dashboard.isDisposed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reveal the dashboard if it is open
|
||||
*/
|
||||
public static reveal() {
|
||||
if (Dashboard.webview) {
|
||||
Dashboard.webview.reveal();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the dashboard webview
|
||||
*/
|
||||
public static async create(extensionPath: string) {
|
||||
|
||||
// Create the preview webview
|
||||
Dashboard.webview = window.createWebviewPanel(
|
||||
'frontMatterDashboard',
|
||||
'FrontMatter Dashboard',
|
||||
ViewColumn.One,
|
||||
{
|
||||
enableScripts: true
|
||||
}
|
||||
);
|
||||
|
||||
Dashboard.isDisposed = false;
|
||||
|
||||
Dashboard.webview.iconPath = {
|
||||
dark: Uri.file(join(extensionPath, 'assets/frontmatter-dark.svg')),
|
||||
light: Uri.file(join(extensionPath, 'assets/frontmatter.svg'))
|
||||
};
|
||||
|
||||
Dashboard.webview.webview.html = Dashboard.getWebviewContent(Dashboard.webview.webview, Uri.parse(extensionPath));
|
||||
|
||||
Dashboard.webview.onDidChangeViewState(() => {
|
||||
if (this.webview?.visible) {
|
||||
console.log(`Dashboard opened`);
|
||||
}
|
||||
});
|
||||
|
||||
Dashboard.webview.onDidDispose(() => {
|
||||
Dashboard.isDisposed = true;
|
||||
});
|
||||
|
||||
Dashboard.webview.webview.onDidReceiveMessage(async (msg) => {
|
||||
switch(msg.command) {
|
||||
case DashboardMessage.getData:
|
||||
Dashboard.getSettings();
|
||||
Dashboard.getPages();
|
||||
break;
|
||||
case DashboardMessage.openFile:
|
||||
openFileInEditor(msg.data);
|
||||
break;
|
||||
case DashboardMessage.createContent:
|
||||
await commands.executeCommand(COMMAND_NAME.createContent);
|
||||
break;
|
||||
case DashboardMessage.updateSetting:
|
||||
Dashboard.updateSetting(msg.data);
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the settings for the dashboard
|
||||
*/
|
||||
private static async getSettings() {
|
||||
Dashboard.postWebviewMessage({
|
||||
command: DashboardCommand.settings,
|
||||
data: {
|
||||
folders: Folders.get(),
|
||||
initialized: await Template.isInitialized(),
|
||||
tags: SettingsHelper.getTaxonomy(TaxonomyType.Tag),
|
||||
categories: SettingsHelper.getTaxonomy(TaxonomyType.Category),
|
||||
openOnStart: SettingsHelper.getConfig().get(SETTINGS_DASHBOARD_OPENONSTART)
|
||||
} as Settings
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a setting from the dashboard
|
||||
*/
|
||||
private static async updateSetting(data: { name: string, value: any }) {
|
||||
await SettingsHelper.updateSetting(data.name, data.value);
|
||||
Dashboard.getSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all the markdown pages
|
||||
*/
|
||||
private static async getPages() {
|
||||
const config = SettingsHelper.getConfig();
|
||||
const wsFolders = workspace.workspaceFolders;
|
||||
const crntWsFolder = wsFolders && wsFolders.length > 0 ? wsFolders[0] : null;
|
||||
|
||||
const descriptionField = config.get(SETTING_SEO_DESCRIPTION_FIELD) as string || "description";
|
||||
const dateField = config.get(SETTING_DATE_FIELD) as string || "date";
|
||||
const staticFolder = config.get<string>(SETTINGS_CONTENT_STATIC_FOLDERS);
|
||||
|
||||
const folderInfo = await Folders.getInfo();
|
||||
const pages: Page[] = [];
|
||||
|
||||
if (folderInfo) {
|
||||
for (const folder of folderInfo) {
|
||||
for (const file of folder.lastModified) {
|
||||
if (file.fileName.endsWith(`.md`) || file.fileName.endsWith(`.mdx`)) {
|
||||
try {
|
||||
const article = ArticleHelper.getFrontMatterByPath(file.filePath);
|
||||
|
||||
if (article?.data.title) {
|
||||
const page: Page = {
|
||||
...article.data,
|
||||
// FrontMatter properties
|
||||
fmGroup: folder.title,
|
||||
fmModified: file.mtime,
|
||||
fmFilePath: file.filePath,
|
||||
fmFileName: file.fileName,
|
||||
// Make sure these are always set
|
||||
title: article?.data.title,
|
||||
slug: article?.data.slug,
|
||||
date: article?.data[dateField] || "",
|
||||
draft: article?.data.draft,
|
||||
description: article?.data[descriptionField] || "",
|
||||
};
|
||||
|
||||
if (article?.data.preview && crntWsFolder) {
|
||||
const previewPath = join(crntWsFolder.uri.fsPath, staticFolder || "", article?.data.preview);
|
||||
const previewUri = Uri.file(previewPath);
|
||||
const preview = Dashboard.webview?.webview.asWebviewUri(previewUri);
|
||||
page.preview = preview?.toString() || "";
|
||||
}
|
||||
|
||||
pages.push(page);
|
||||
}
|
||||
} catch (error) {
|
||||
Notifications.error(`File error: ${file.filePath} - ${error?.message || error}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Dashboard.postWebviewMessage({
|
||||
command: DashboardCommand.pages,
|
||||
data: pages
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Post data to the dashboard
|
||||
* @param msg
|
||||
*/
|
||||
private static postWebviewMessage(msg: { command: DashboardCommand, data?: any }) {
|
||||
Dashboard.webview?.webview.postMessage(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the webview HTML contents
|
||||
* @param webView
|
||||
*/
|
||||
private static getWebviewContent(webView: Webview, extensionPath: Uri): string {
|
||||
const scriptUri = webView.asWebviewUri(Uri.joinPath(extensionPath, 'dist', 'pages.js'));
|
||||
|
||||
const nonce = getNonce();
|
||||
|
||||
return `
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" style="width:100%;height:100%;margin:0;padding:0;">
|
||||
<head>
|
||||
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src ${`vscode-file://vscode-app`} ${webView.cspSource} https://api.visitorbadge.io 'self' 'unsafe-inline'; script-src 'nonce-${nonce}'; style-src ${webView.cspSource} 'self' 'unsafe-inline'; font-src ${webView.cspSource}">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
||||
<title>Front Matter Dashboard</title>
|
||||
</head>
|
||||
<body style="width:100%;height:100%;margin:0;padding:0;overflow:hidden" class="bg-gray-100 text-vulcan-500 dark:bg-vulcan-500 dark:text-whisper-500">
|
||||
<div id="app" style="width:100%;height:100%;margin:0;padding:0;"></div>
|
||||
|
||||
<img style="display:none" src="https://api.visitorbadge.io/api/combined?user=estruyf&repo=frontmatter-usage&countColor=%23263759" alt="Daily usage" />
|
||||
|
||||
<script nonce="${nonce}" src="${scriptUri}"></script>
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
}
|
||||
}
|
||||
@@ -111,51 +111,84 @@ export class Folders {
|
||||
*/
|
||||
public static getFolderPath(folder: Uri) {
|
||||
let folderPath = "";
|
||||
const wsFolder = Folders.getWorkspaceFolder();
|
||||
if (folder && folder.fsPath) {
|
||||
folderPath = folder.fsPath;
|
||||
} else if (workspace.workspaceFolders && workspace.workspaceFolders.length > 0) {
|
||||
folderPath = workspace.workspaceFolders[0].uri.fsPath;
|
||||
} else if (wsFolder) {
|
||||
folderPath = wsFolder.fsPath;
|
||||
}
|
||||
return folderPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the workspace folder
|
||||
*/
|
||||
public static getWorkspaceFolder(): Uri | undefined {
|
||||
const folders = workspace.workspaceFolders;
|
||||
if (folders && folders.length > 0) {
|
||||
return folders[0].uri;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the project
|
||||
*/
|
||||
public static getProjectFolderName(): string {
|
||||
const wsFolder = Folders.getWorkspaceFolder();
|
||||
if (wsFolder) {
|
||||
// const projectFolder = wsFolder?.fsPath.split('\\').join('/').split('/').pop();
|
||||
return basename(wsFolder.fsPath);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the registered folders information
|
||||
*/
|
||||
public static async getInfo(): Promise<FolderInfo[] | null> {
|
||||
public static async getInfo(limit?: number): Promise<FolderInfo[] | null> {
|
||||
const folders = Folders.get();
|
||||
if (folders && folders.length > 0) {
|
||||
let folderInfo: FolderInfo[] = [];
|
||||
|
||||
for (const folder of folders) {
|
||||
try {
|
||||
const folderPath = Uri.file(folder.fsPath);
|
||||
const files = await workspace.fs.readDirectory(folderPath);
|
||||
if (files) {
|
||||
let fileStats: FileInfo[] = [];
|
||||
const projectName = Folders.getProjectFolderName();
|
||||
let projectStart = folder.fsPath.split(projectName).pop();
|
||||
if (projectStart) {
|
||||
projectStart = projectStart.startsWith('/') ? projectStart.substr(1) : projectStart;
|
||||
const mdFiles = await workspace.findFiles(join(projectStart, '**/*.md'));
|
||||
const mdxFiles = await workspace.findFiles(join(projectStart, '**/*.mdx'));
|
||||
let files = [...mdFiles, ...mdxFiles];
|
||||
if (files) {
|
||||
let fileStats: FileInfo[] = [];
|
||||
|
||||
for (const file of files) {
|
||||
try {
|
||||
const fileName = file[0];
|
||||
const filePath = Uri.file(join(folderPath.fsPath, fileName));
|
||||
const stats = await workspace.fs.stat(filePath);
|
||||
fileStats.push({
|
||||
filePath: filePath.fsPath,
|
||||
fileName,
|
||||
...stats
|
||||
});
|
||||
} catch (error) {
|
||||
// Skip the file
|
||||
for (const file of files) {
|
||||
try {
|
||||
const fileName = basename(file.fsPath);
|
||||
const stats = await workspace.fs.stat(file);
|
||||
fileStats.push({
|
||||
filePath: file.fsPath,
|
||||
fileName,
|
||||
...stats
|
||||
});
|
||||
} catch (error) {
|
||||
// Skip the file
|
||||
}
|
||||
}
|
||||
|
||||
fileStats = fileStats.sort((a, b) => b.mtime - a.mtime);
|
||||
|
||||
if (limit) {
|
||||
fileStats = fileStats.slice(0, limit);
|
||||
}
|
||||
|
||||
folderInfo.push({
|
||||
title: folder.title,
|
||||
files: files.length,
|
||||
lastModified: fileStats
|
||||
});
|
||||
}
|
||||
|
||||
fileStats = fileStats.sort((a, b) => b.mtime - a.mtime).slice(0, 10);
|
||||
|
||||
folderInfo.push({
|
||||
title: folder.title,
|
||||
files: files.length,
|
||||
lastModified: fileStats
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
// Skip the current folder
|
||||
@@ -172,7 +205,7 @@ export class Folders {
|
||||
* Get the folder settings
|
||||
* @returns
|
||||
*/
|
||||
private static get() {
|
||||
public static get() {
|
||||
const config = SettingsHelper.getConfig();
|
||||
const folders: ContentFolder[] = config.get(SETTINGS_CONTENT_FOLDERS) as ContentFolder[];
|
||||
return folders;
|
||||
|
||||
@@ -23,4 +23,5 @@ export const COMMAND_NAME = {
|
||||
createTemplate: getCommandName("createTemplate"),
|
||||
collapseSections: getCommandName("collapseSections"),
|
||||
preview: getCommandName("preview"),
|
||||
dashboard: getCommandName("dashboard"),
|
||||
};
|
||||
@@ -1,7 +1,6 @@
|
||||
|
||||
|
||||
export const CONTEXT = {
|
||||
canInit: "frontMatterCanInit",
|
||||
canOpenPreview: "frontMatterCanOpenPreview",
|
||||
canOpenDashboard: "frontMatterCanOpenDashboard",
|
||||
registeredFolders: 'frontMatter.registeredFolders'
|
||||
};
|
||||
@@ -34,4 +34,7 @@ export const SETTING_CUSTOM_SCRIPTS = "custom.scripts";
|
||||
|
||||
export const SETTING_AUTO_UPDATE_DATE = "content.autoUpdateDate";
|
||||
export const SETTINGS_CONTENT_FOLDERS = "content.folders";
|
||||
export const SETTINGS_CONTENT_FRONTMATTER_HIGHLIGHT = "content.fmHighlight";
|
||||
export const SETTINGS_CONTENT_STATIC_FOLDERS = "content.publicFolder";
|
||||
export const SETTINGS_CONTENT_FRONTMATTER_HIGHLIGHT = "content.fmHighlight";
|
||||
|
||||
export const SETTINGS_DASHBOARD_OPENONSTART = "dashboard.openOnStart";
|
||||
@@ -1,3 +1,4 @@
|
||||
import { Dashboard } from './commands/Dashboard';
|
||||
import * as vscode from 'vscode';
|
||||
import { Article, Settings, StatusListener } from './commands';
|
||||
import { Folders } from './commands/Folders';
|
||||
@@ -20,6 +21,13 @@ const mdSelector: vscode.DocumentSelector = { language: 'markdown', scheme: 'fil
|
||||
export async function activate({ subscriptions, extensionUri, extensionPath }: vscode.ExtensionContext) {
|
||||
collection = vscode.languages.createDiagnosticCollection('frontMatter');
|
||||
|
||||
// Pages dashboard
|
||||
Dashboard.init(extensionPath);
|
||||
subscriptions.push(vscode.commands.registerCommand(COMMAND_NAME.dashboard, () => {
|
||||
Dashboard.open(extensionPath);
|
||||
}));
|
||||
|
||||
// Register the explorer view
|
||||
const explorerSidebar = ExplorerView.getInstance(extensionUri);
|
||||
let explorerView = vscode.window.registerWebviewViewProvider(ExplorerView.viewType, explorerSidebar, {
|
||||
webviewOptions: {
|
||||
@@ -50,25 +58,15 @@ export async function activate({ subscriptions, extensionUri, extensionPath }: v
|
||||
Settings.create(TaxonomyType.Category);
|
||||
});
|
||||
|
||||
let exportTaxonomy = vscode.commands.registerCommand(COMMAND_NAME.exportTaxonomy, () => {
|
||||
Settings.export();
|
||||
});
|
||||
let exportTaxonomy = vscode.commands.registerCommand(COMMAND_NAME.exportTaxonomy, Settings.export);
|
||||
|
||||
let remap = vscode.commands.registerCommand(COMMAND_NAME.remap, () => {
|
||||
Settings.remap();
|
||||
});
|
||||
let remap = vscode.commands.registerCommand(COMMAND_NAME.remap, Settings.remap);
|
||||
|
||||
let setDate = vscode.commands.registerCommand(COMMAND_NAME.setDate, () => {
|
||||
Article.setDate();
|
||||
});
|
||||
let setDate = vscode.commands.registerCommand(COMMAND_NAME.setDate, Article.setDate);
|
||||
|
||||
let setLastModifiedDate = vscode.commands.registerCommand(COMMAND_NAME.setLastModifiedDate, () => {
|
||||
Article.setLastModifiedDate();
|
||||
});
|
||||
let setLastModifiedDate = vscode.commands.registerCommand(COMMAND_NAME.setLastModifiedDate, Article.setLastModifiedDate);
|
||||
|
||||
let generateSlug = vscode.commands.registerCommand(COMMAND_NAME.generateSlug, () => {
|
||||
Article.generateSlug();
|
||||
});
|
||||
let generateSlug = vscode.commands.registerCommand(COMMAND_NAME.generateSlug, Article.generateSlug);
|
||||
|
||||
let createFromTemplate = vscode.commands.registerCommand(COMMAND_NAME.createFromTemplate, (folder: vscode.Uri) => {
|
||||
const folderPath = Folders.getFolderPath(folder);
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { CommandToCode } from "../CommandToCode";
|
||||
import { DashboardMessage } from './../pagesView/DashboardMessage';
|
||||
import { CommandToCode } from "../viewpanel/CommandToCode";
|
||||
|
||||
|
||||
interface ClientVsCode<T> {
|
||||
getState: () => T;
|
||||
@@ -16,7 +18,7 @@ export class MessageHelper {
|
||||
return MessageHelper.vscode;
|
||||
}
|
||||
|
||||
public static sendMessage = (command: CommandToCode, data?: any) => {
|
||||
public static sendMessage = (command: CommandToCode | DashboardMessage, data?: any) => {
|
||||
if (data) {
|
||||
MessageHelper.vscode.postMessage({ command, data });
|
||||
} else {
|
||||
@@ -8,6 +8,11 @@ export class SettingsHelper {
|
||||
return vscode.workspace.getConfiguration(CONFIG_KEY);
|
||||
}
|
||||
|
||||
public static async updateSetting(name: string, value: any) {
|
||||
const config = vscode.workspace.getConfiguration(CONFIG_KEY);
|
||||
await config.update(name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the taxonomy settings
|
||||
*
|
||||
|
||||
10
src/helpers/getNonce.ts
Normal file
10
src/helpers/getNonce.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
|
||||
export const getNonce = () => {
|
||||
let text = '';
|
||||
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||
for (let i = 0; i < 32; i++) {
|
||||
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
||||
}
|
||||
return text;
|
||||
};
|
||||
13
src/helpers/openFileInEditor.ts
Normal file
13
src/helpers/openFileInEditor.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Uri, workspace, window } from "vscode";
|
||||
import { Notifications } from "./Notifications";
|
||||
|
||||
export const openFileInEditor = async (filePath: string) => {
|
||||
if (filePath) {
|
||||
try {
|
||||
const doc = await workspace.openTextDocument(Uri.file(filePath));
|
||||
await window.showTextDocument(doc, 1, false);
|
||||
} catch (e) {
|
||||
Notifications.error(`Couldn't open the file.`);
|
||||
}
|
||||
}
|
||||
};
|
||||
28
src/hooks/useDarkMode.tsx
Normal file
28
src/hooks/useDarkMode.tsx
Normal file
@@ -0,0 +1,28 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
|
||||
export default function useDarkMode() {
|
||||
|
||||
const setTheme = (elm: HTMLElement) => {
|
||||
if (elm) {
|
||||
const darkMode = elm.classList.contains('vscode-dark');
|
||||
document.documentElement.classList.remove(`${darkMode ? "light" : "dark"}`);
|
||||
document.documentElement.classList.add(`${darkMode ? "dark" : "light"}`);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const mutationObserver = new MutationObserver((mutationsList, observer) => {
|
||||
const last = mutationsList.filter(item => item.type === "attributes" || item.attributeName === 'class').pop();
|
||||
setTheme(last?.target as HTMLElement);
|
||||
});
|
||||
|
||||
setTheme(document.body);
|
||||
|
||||
mutationObserver.observe(document.body, { childList: false, attributes: true })
|
||||
|
||||
return () => {
|
||||
mutationObserver.disconnect();
|
||||
};
|
||||
}, ['']);
|
||||
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
export function useDebounce(value: string, delay: number) {
|
||||
export function useDebounce<T>(value: T, delay: number) {
|
||||
// State and setters for debounced value
|
||||
const [debouncedValue, setDebouncedValue] = useState(value);
|
||||
const [debouncedValue, setDebouncedValue] = useState<T>(value);
|
||||
|
||||
useEffect(
|
||||
() => {
|
||||
5
src/pagesView/DashboardCommand.ts
Normal file
5
src/pagesView/DashboardCommand.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export enum DashboardCommand {
|
||||
loading = "loading",
|
||||
pages = "pages",
|
||||
settings = "settings"
|
||||
}
|
||||
7
src/pagesView/DashboardMessage.ts
Normal file
7
src/pagesView/DashboardMessage.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export enum DashboardMessage {
|
||||
getData = 'getData',
|
||||
openFile = 'openFile',
|
||||
getTheme = 'getTheme',
|
||||
createContent = 'createContent',
|
||||
updateSetting = 'updateSetting',
|
||||
}
|
||||
19
src/pagesView/components/Button.tsx
Normal file
19
src/pagesView/components/Button.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
import * as React from 'react';
|
||||
|
||||
export interface IButtonProps {
|
||||
disabled?: boolean;
|
||||
onClick: () => void;
|
||||
}
|
||||
|
||||
export const Button: React.FunctionComponent<IButtonProps> = ({onClick, disabled, children}: React.PropsWithChildren<IButtonProps>) => {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
className="inline-flex items-center px-3 py-2 border border-transparent text-sm leading-4 font-medium text-white dark:text-vulcan-500 bg-teal-600 hover:bg-teal-700 focus:outline-none disabled:bg-gray-500"
|
||||
onClick={onClick}
|
||||
disabled={disabled}
|
||||
>
|
||||
{children}
|
||||
</button>
|
||||
);
|
||||
};
|
||||
53
src/pagesView/components/Dashboard.tsx
Normal file
53
src/pagesView/components/Dashboard.tsx
Normal file
@@ -0,0 +1,53 @@
|
||||
import * as React from 'react';
|
||||
import { Spinner } from './Spinner';
|
||||
import useMessages from '../hooks/useMessages';
|
||||
import { Overview } from './Overview';
|
||||
import { Header } from './Header';
|
||||
import { Tab } from '../constants/Tab';
|
||||
import { SortOption } from '../constants/SortOption';
|
||||
import useDarkMode from '../../hooks/useDarkMode';
|
||||
import usePages from '../hooks/usePages';
|
||||
|
||||
export interface IDashboardProps {}
|
||||
|
||||
export const Dashboard: React.FunctionComponent<IDashboardProps> = ({}: React.PropsWithChildren<IDashboardProps>) => {
|
||||
const { loading, pages, settings } = useMessages();
|
||||
const [ tab, setTab ] = React.useState(Tab.All);
|
||||
const [ sorting, setSorting ] = React.useState(SortOption.LastModified);
|
||||
const [ group, setGroup ] = React.useState<string | null>(null);
|
||||
const [ search, setSearch ] = React.useState<string | null>(null);
|
||||
const [ tag, setTag ] = React.useState<string | null>(null);
|
||||
const [ category, setCategory ] = React.useState<string | null>(null);
|
||||
const { pageItems } = usePages(pages, tab, sorting, group, search, tag, category);
|
||||
useDarkMode();
|
||||
|
||||
const pageGroups = [...new Set(pages.map(page => page.fmGroup))];
|
||||
|
||||
return (
|
||||
<main className={`h-full w-full`}>
|
||||
<div className="flex flex-col h-full overflow-auto">
|
||||
<Header currentTab={tab}
|
||||
currentSorting={sorting}
|
||||
groups={pageGroups}
|
||||
crntGroup={group}
|
||||
totalPages={pageItems.length}
|
||||
crntTag={tag}
|
||||
crntCategory={category}
|
||||
switchTab={(tabId: Tab) => setTab(tabId)}
|
||||
switchSorting={(sortId: SortOption) => setSorting(sortId)}
|
||||
switchGroup={(groupId: string | null) => setGroup(groupId)}
|
||||
switchTag={(tagId: string | null) => setTag(tagId)}
|
||||
switchCategory={(categoryId: string | null) => setCategory(categoryId)}
|
||||
onSearch={(value: string | null) => setSearch(value)}
|
||||
settings={settings}
|
||||
/>
|
||||
|
||||
<div className="flex-grow max-w-7xl mx-auto py-6 px-4">
|
||||
{ loading ? <Spinner /> : <Overview pages={pageItems} settings={settings} /> }
|
||||
</div>
|
||||
|
||||
<p className={`text-vulcan-50 dark:text-whisper-900 py-2 text-center`}>If you find FrontMatter useful, please consider <a className={`text-vulcan-500 dark:text-whisper-500 hover:text-vulcan-600 dark:hover:text-whisper-300`} href="https://github.com/sponsors/estruyf" title="Sponsor Front Matter">sponsoring</a> it, or if you use FrontMatter for work, please encourage your employer to <a className={`text-vulcan-500 dark:text-whisper-500 hover:text-vulcan-600 dark:hover:text-whisper-300`} href="https://github.com/sponsors/estruyf" title="Sponsor Front Matter">sponsoring</a> it.</p>
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
};
|
||||
28
src/pagesView/components/DateField.tsx
Normal file
28
src/pagesView/components/DateField.tsx
Normal file
@@ -0,0 +1,28 @@
|
||||
import { format, parseJSON } from 'date-fns';
|
||||
import * as React from 'react';
|
||||
|
||||
export interface IDateFieldProps {
|
||||
value: Date | string;
|
||||
}
|
||||
|
||||
export const DateField: React.FunctionComponent<IDateFieldProps> = ({value}: React.PropsWithChildren<IDateFieldProps>) => {
|
||||
const [ dateValue, setDateValue ] = React.useState<string>("");
|
||||
|
||||
React.useEffect(() => {
|
||||
try {
|
||||
const parsedValue = typeof value === 'string' ? parseJSON(value) : value;
|
||||
const dateString = format(parsedValue, 'yyyy-MM-dd');
|
||||
setDateValue(dateString);
|
||||
} catch (e) {
|
||||
// Date is invalid
|
||||
}
|
||||
}, [value]);
|
||||
|
||||
if (!dateValue) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<span className={`text-vulcan-100 dark:text-whisper-900 text-xs`}>{dateValue}</span>
|
||||
);
|
||||
};
|
||||
48
src/pagesView/components/Filter.tsx
Normal file
48
src/pagesView/components/Filter.tsx
Normal file
@@ -0,0 +1,48 @@
|
||||
import { Menu } from '@headlessui/react';
|
||||
import * as React from 'react';
|
||||
import { MenuButton } from './MenuButton';
|
||||
import { MenuItem } from './MenuItem';
|
||||
import { MenuItems } from './MenuItems';
|
||||
|
||||
export interface IFilterProps {
|
||||
label: string;
|
||||
items: string[];
|
||||
activeItem: string | null;
|
||||
onClick: (item: string | null) => void;
|
||||
}
|
||||
|
||||
const DEFAULT_VALUE = "No filter";
|
||||
|
||||
export const Filter: React.FunctionComponent<IFilterProps> = ({label, activeItem, items, onClick}: React.PropsWithChildren<IFilterProps>) => {
|
||||
|
||||
console.log(items);
|
||||
|
||||
if (!items || items.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex items-center ml-6">
|
||||
<Menu as="div" className="relative z-10 inline-block text-left">
|
||||
<MenuButton label={label} title={activeItem || DEFAULT_VALUE} />
|
||||
|
||||
<MenuItems>
|
||||
<MenuItem
|
||||
title={DEFAULT_VALUE}
|
||||
value={null}
|
||||
isCurrent={!!activeItem}
|
||||
onClick={() => onClick(null)} />
|
||||
|
||||
{items.map((option) => (
|
||||
<MenuItem
|
||||
key={option}
|
||||
title={option}
|
||||
value={option}
|
||||
isCurrent={option === activeItem}
|
||||
onClick={() => onClick(option)} />
|
||||
))}
|
||||
</MenuItems>
|
||||
</Menu>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
46
src/pagesView/components/Grouping.tsx
Normal file
46
src/pagesView/components/Grouping.tsx
Normal file
@@ -0,0 +1,46 @@
|
||||
import { Menu, Transition } from '@headlessui/react';
|
||||
import { ChevronDownIcon } from '@heroicons/react/solid';
|
||||
import * as React from 'react';
|
||||
import { Fragment } from 'react';
|
||||
import { MenuButton } from './MenuButton';
|
||||
import { MenuItem } from './MenuItem';
|
||||
import { MenuItems } from './MenuItems';
|
||||
|
||||
export interface IGroupingProps {
|
||||
groups: string[];
|
||||
crntGroup: string | null;
|
||||
switchGroup: (group: string | null) => void;
|
||||
}
|
||||
|
||||
const DEFAULT_TYPE = "All types";
|
||||
|
||||
export const Grouping: React.FunctionComponent<IGroupingProps> = ({groups, crntGroup, switchGroup}: React.PropsWithChildren<IGroupingProps>) => {
|
||||
if (groups.length <= 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex items-center ml-6">
|
||||
<Menu as="div" className="relative z-10 inline-block text-left">
|
||||
<MenuButton label={`Showing`} title={crntGroup || DEFAULT_TYPE} />
|
||||
|
||||
<MenuItems>
|
||||
<MenuItem
|
||||
title={DEFAULT_TYPE}
|
||||
value={null}
|
||||
isCurrent={!crntGroup}
|
||||
onClick={switchGroup} />
|
||||
|
||||
{groups.map((option) => (
|
||||
<MenuItem
|
||||
key={option}
|
||||
title={option}
|
||||
value={option}
|
||||
isCurrent={option === crntGroup}
|
||||
onClick={switchGroup} />
|
||||
))}
|
||||
</MenuItems>
|
||||
</Menu>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
75
src/pagesView/components/Header.tsx
Normal file
75
src/pagesView/components/Header.tsx
Normal file
@@ -0,0 +1,75 @@
|
||||
import * as React from 'react';
|
||||
import { Tab } from '../constants/Tab';
|
||||
import { SortOption } from '../constants/SortOption';
|
||||
import { Navigation } from './Navigation';
|
||||
import { Sorting } from './Sorting';
|
||||
import { Grouping } from './Grouping';
|
||||
import { MessageHelper } from '../../helpers/MessageHelper';
|
||||
import { DashboardMessage } from '../DashboardMessage';
|
||||
import { Searchbox } from './Searchbox';
|
||||
import { Settings } from '../models/Settings';
|
||||
import { Startup } from './Startup';
|
||||
import { Button } from './Button';
|
||||
import { Filter } from './Filter';
|
||||
|
||||
export interface IHeaderProps {
|
||||
settings: Settings;
|
||||
|
||||
// Navigation
|
||||
currentTab: Tab;
|
||||
totalPages: number;
|
||||
switchTab: (tabId: Tab) => void;
|
||||
|
||||
// Sorting
|
||||
currentSorting: SortOption;
|
||||
switchSorting: (sortId: SortOption) => void;
|
||||
|
||||
// Grouping
|
||||
groups: string[];
|
||||
crntGroup: string | null;
|
||||
switchGroup: (group: string | null) => void;
|
||||
|
||||
// Searching
|
||||
onSearch: (value: string | null) => void;
|
||||
|
||||
// Tags
|
||||
crntTag: string | null;
|
||||
switchTag: (tag: string | null) => void;
|
||||
|
||||
// Categories
|
||||
crntCategory: string | null;
|
||||
switchCategory: (category: string | null) => void;
|
||||
}
|
||||
|
||||
export const Header: React.FunctionComponent<IHeaderProps> = ({currentTab, currentSorting, switchSorting, switchTab, totalPages, crntGroup, groups, switchGroup, onSearch, settings, switchTag, crntTag, switchCategory, crntCategory}: React.PropsWithChildren<IHeaderProps>) => {
|
||||
|
||||
const createContent = () => {
|
||||
MessageHelper.sendMessage(DashboardMessage.createContent);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={`w-full max-w-7xl mx-auto sticky top-0 z-40 bg-gray-100 dark:bg-vulcan-500`}>
|
||||
<div className={`px-4 my-2 flex items-center justify-between`}>
|
||||
<Searchbox onSearch={onSearch} />
|
||||
|
||||
<div className={`flex items-center space-x-4`}>
|
||||
<Startup settings={settings} />
|
||||
|
||||
<Button onClick={createContent} disabled={!settings.initialized}>Create content</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="px-4 flex items-center border-b border-gray-200 dark:border-whisper-600">
|
||||
<Navigation currentTab={currentTab} totalPages={totalPages} switchTab={switchTab} />
|
||||
|
||||
<Grouping crntGroup={crntGroup} groups={groups} switchGroup={switchGroup} />
|
||||
|
||||
<Filter label={`Tag filter`} activeItem={crntTag} items={settings.tags} onClick={switchTag} />
|
||||
|
||||
<Filter label={`Category filter`} activeItem={crntCategory} items={settings.categories} onClick={switchCategory} />
|
||||
|
||||
<Sorting currentSorting={currentSorting} switchSorting={switchSorting} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
47
src/pagesView/components/Item.tsx
Normal file
47
src/pagesView/components/Item.tsx
Normal file
@@ -0,0 +1,47 @@
|
||||
import * as React from 'react';
|
||||
import { MessageHelper } from '../../helpers/MessageHelper';
|
||||
import { MarkdownIcon } from '../../viewpanel/components/Icons/MarkdownIcon';
|
||||
import { DashboardMessage } from '../DashboardMessage';
|
||||
import { Page } from '../models/Page';
|
||||
import { DateField } from './DateField';
|
||||
import { Status } from './Status';
|
||||
|
||||
export interface IItemProps extends Page {}
|
||||
|
||||
export const Item: React.FunctionComponent<IItemProps> = ({ fmFilePath, date, title, draft, description, preview }: React.PropsWithChildren<IItemProps>) => {
|
||||
|
||||
const openFile = () => {
|
||||
MessageHelper.sendMessage(DashboardMessage.openFile, fmFilePath);
|
||||
};
|
||||
|
||||
return (
|
||||
<li className="relative">
|
||||
<button className={`group cursor-pointer flex flex-wrap items-start content-start h-full w-full bg-gray-50 dark:bg-vulcan-200 text-vulcan-500 dark:text-whisper-500 text-left overflow-hidden shadow-md hover:shadow-xl dark:hover:bg-vulcan-100`}
|
||||
onClick={openFile}>
|
||||
<div className="relative h-36 w-full overflow-hidden border-b border-gray-100 dark:border-vulcan-100 dark:group-hover:border-vulcan-200">
|
||||
{
|
||||
preview ? (
|
||||
<img src={`${preview}`} alt={title} className="absolute inset-0 h-full w-full object-cover" loading="lazy" />
|
||||
) : (
|
||||
<div className={`flex items-center justify-center bg-whisper-500 dark:bg-vulcan-200 dark:group-hover:bg-vulcan-100`}>
|
||||
<MarkdownIcon className={`h-32 text-vulcan-100 dark:text-whisper-100`} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
</div>
|
||||
|
||||
<div className="p-4 w-full">
|
||||
<div className={`flex justify-between items-center`}>
|
||||
<Status draft={!!draft} />
|
||||
|
||||
<DateField value={date} />
|
||||
</div>
|
||||
|
||||
<h2 className="mt-2 mb-2 font-bold">{title}</h2>
|
||||
|
||||
<p className="text-xs text-vulcan-200 dark:text-whisper-800">{description}</p>
|
||||
</div>
|
||||
</button>
|
||||
</li>
|
||||
);
|
||||
};
|
||||
11
src/pagesView/components/List.tsx
Normal file
11
src/pagesView/components/List.tsx
Normal file
@@ -0,0 +1,11 @@
|
||||
import * as React from 'react';
|
||||
|
||||
export interface IListProps {}
|
||||
|
||||
export const List: React.FunctionComponent<IListProps> = ({children}: React.PropsWithChildren<IListProps>) => {
|
||||
return (
|
||||
<ul role="list" className="grid grid-cols-2 gap-x-4 gap-y-8 sm:grid-cols-3 sm:gap-x-6 lg:grid-cols-4 xl:gap-x-8">
|
||||
{children}
|
||||
</ul>
|
||||
);
|
||||
};
|
||||
23
src/pagesView/components/MenuButton.tsx
Normal file
23
src/pagesView/components/MenuButton.tsx
Normal file
@@ -0,0 +1,23 @@
|
||||
import { Menu } from '@headlessui/react';
|
||||
import { ChevronDownIcon } from '@heroicons/react/solid';
|
||||
import * as React from 'react';
|
||||
|
||||
export interface IMenuButtonProps {
|
||||
label: string;
|
||||
title: string;
|
||||
}
|
||||
|
||||
export const MenuButton: React.FunctionComponent<IMenuButtonProps> = ({label, title}: React.PropsWithChildren<IMenuButtonProps>) => {
|
||||
return (
|
||||
<div>
|
||||
<span className={`text-gray-500 dark:text-whisper-700 mr-2 font-medium`}>{label}:</span>
|
||||
<Menu.Button className="group inline-flex justify-center text-sm font-medium text-vulcan-500 hover:text-vulcan-600 dark:text-whisper-500 dark:hover:text-whisper-600">
|
||||
{title}
|
||||
<ChevronDownIcon
|
||||
className="flex-shrink-0 -mr-1 ml-1 h-5 w-5 text-gray-400 group-hover:text-gray-500 dark:text-whisper-600 dark:group-hover:text-whisper-700"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</Menu.Button>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
22
src/pagesView/components/MenuItem.tsx
Normal file
22
src/pagesView/components/MenuItem.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import { Menu } from '@headlessui/react';
|
||||
import * as React from 'react';
|
||||
|
||||
export interface IMenuItemProps {
|
||||
title: string;
|
||||
value: any;
|
||||
isCurrent: boolean;
|
||||
onClick: (value: any) => void;
|
||||
}
|
||||
|
||||
export const MenuItem: React.FunctionComponent<IMenuItemProps> = ({title, value, isCurrent, onClick}: React.PropsWithChildren<IMenuItemProps>) => {
|
||||
return (
|
||||
<Menu.Item>
|
||||
<button
|
||||
onClick={() => onClick(value)}
|
||||
className={`${!isCurrent ? `text-vulcan-500 dark:text-whisper-500` : `text-gray-500 dark:text-whisper-900`} block px-4 py-2 text-sm font-medium w-full text-left hover:bg-gray-100 hover:text-gray-700 dark:hover:text-whisper-600 dark:hover:bg-vulcan-100`}
|
||||
>
|
||||
{title}
|
||||
</button>
|
||||
</Menu.Item>
|
||||
);
|
||||
};
|
||||
25
src/pagesView/components/MenuItems.tsx
Normal file
25
src/pagesView/components/MenuItems.tsx
Normal file
@@ -0,0 +1,25 @@
|
||||
import { Menu, Transition } from '@headlessui/react';
|
||||
import * as React from 'react';
|
||||
import { Fragment } from 'react';
|
||||
|
||||
export interface IMenuItemsProps {}
|
||||
|
||||
export const MenuItems: React.FunctionComponent<IMenuItemsProps> = ({children}: React.PropsWithChildren<IMenuItemsProps>) => {
|
||||
return (
|
||||
<Transition
|
||||
as={Fragment}
|
||||
enter="transition ease-out duration-100"
|
||||
enterFrom="transform opacity-0 scale-95"
|
||||
enterTo="transform opacity-100 scale-100"
|
||||
leave="transition ease-in duration-75"
|
||||
leaveFrom="transform opacity-100 scale-100"
|
||||
leaveTo="transform opacity-0 scale-95"
|
||||
>
|
||||
<Menu.Items className="origin-top-right absolute right-0 z-10 mt-2 w-40 rounded-md shadow-2xl bg-white dark:bg-vulcan-500 ring-1 ring-vulcan-400 dark:ring-white ring-opacity-5 focus:outline-none text-sm max-h-96 overflow-auto">
|
||||
<div className="py-1">
|
||||
{children}
|
||||
</div>
|
||||
</Menu.Items>
|
||||
</Transition>
|
||||
);
|
||||
};
|
||||
32
src/pagesView/components/Navigation.tsx
Normal file
32
src/pagesView/components/Navigation.tsx
Normal file
@@ -0,0 +1,32 @@
|
||||
import * as React from 'react';
|
||||
import { Tab } from '../constants/Tab';
|
||||
|
||||
export interface INavigationProps {
|
||||
currentTab: Tab;
|
||||
totalPages: number;
|
||||
switchTab: (tabId: Tab) => void;
|
||||
}
|
||||
|
||||
export const tabs = [
|
||||
{ name: 'All articles', id: Tab.All},
|
||||
{ name: 'Published', id: Tab.Published },
|
||||
{ name: 'In draft', id: Tab.Draft }
|
||||
];
|
||||
|
||||
export const Navigation: React.FunctionComponent<INavigationProps> = ({currentTab, totalPages, switchTab}: React.PropsWithChildren<INavigationProps>) => {
|
||||
|
||||
return (
|
||||
<nav className="flex-1 -mb-px flex space-x-6 xl:space-x-8" aria-label="Tabs">
|
||||
{tabs.map((tab) => (
|
||||
<button
|
||||
key={tab.name}
|
||||
className={`${tab.id === currentTab ? `border-teal-900 dark:border-teal-300 text-teal-900 dark:text-teal-300` : `border-transparent text-gray-500 dark:text-whisper-600 hover:text-gray-700 dark:hover:text-whisper-700 hover:border-gray-300 dark:hover:border-whisper-500`} whitespace-nowrap py-2 px-1 border-b-2 font-medium text-sm`}
|
||||
aria-current={tab.id === currentTab ? 'page' : undefined}
|
||||
onClick={() => switchTab(tab.id)}
|
||||
>
|
||||
{tab.name}{(tab.id === currentTab && totalPages) ? ` (${totalPages})` : ''}
|
||||
</button>
|
||||
))}
|
||||
</nav>
|
||||
);
|
||||
};
|
||||
40
src/pagesView/components/Overview.tsx
Normal file
40
src/pagesView/components/Overview.tsx
Normal file
@@ -0,0 +1,40 @@
|
||||
import * as React from 'react';
|
||||
import { MarkdownIcon } from '../../viewpanel/components/Icons/MarkdownIcon';
|
||||
import { Page } from '../models/Page';
|
||||
import { Settings } from '../models/Settings';
|
||||
import { Item } from './Item';
|
||||
import { List } from './List';
|
||||
|
||||
export interface IOverviewProps {
|
||||
pages: Page[];
|
||||
|
||||
settings: Settings;
|
||||
}
|
||||
|
||||
export const Overview: React.FunctionComponent<IOverviewProps> = ({pages, settings}: React.PropsWithChildren<IOverviewProps>) => {
|
||||
|
||||
if (!pages || !pages.length) {
|
||||
return (
|
||||
<div className={`flex items-center justify-center h-full`}>
|
||||
<div className={`max-w-xl text-center`}>
|
||||
<MarkdownIcon className={`text-vulcan-300 dark:text-whisper-800 h-32 mx-auto`} />
|
||||
{
|
||||
settings?.folders?.length > 0 ? (
|
||||
<p className={`text-xl font-medium`}>No Markdown to show</p>
|
||||
) : (
|
||||
<p className={`text-lg font-medium`}>Make sure you registered a content folder in your project to let Front Matter find the contents.</p>
|
||||
)
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<List>
|
||||
{pages.map(page => (
|
||||
<Item key={page.slug} {...page} />
|
||||
))}
|
||||
</List>
|
||||
);
|
||||
};
|
||||
42
src/pagesView/components/Searchbox.tsx
Normal file
42
src/pagesView/components/Searchbox.tsx
Normal file
@@ -0,0 +1,42 @@
|
||||
import { FilterIcon, SearchIcon } from '@heroicons/react/solid';
|
||||
import * as React from 'react';
|
||||
import { useDebounce } from '../../hooks/useDebounce';
|
||||
|
||||
export interface ISearchboxProps {
|
||||
onSearch: (searchText: string) => void;
|
||||
}
|
||||
|
||||
export const Searchbox: React.FunctionComponent<ISearchboxProps> = ({onSearch}: React.PropsWithChildren<ISearchboxProps>) => {
|
||||
const [ value, setValue ] = React.useState('');
|
||||
const debounceSearch = useDebounce<string>(value, 500);
|
||||
|
||||
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
setValue(event.target.value);
|
||||
};
|
||||
|
||||
React.useEffect(() => {
|
||||
onSearch(debounceSearch);
|
||||
}, [debounceSearch]);
|
||||
|
||||
return (
|
||||
<div className="flex space-x-4">
|
||||
<div className="flex-1 min-w-0">
|
||||
<label htmlFor="search" className="sr-only">Search</label>
|
||||
<div className="relative flex justify-center">
|
||||
<div className="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
|
||||
<SearchIcon className="h-5 w-5 text-gray-400" aria-hidden="true" />
|
||||
</div>
|
||||
<input
|
||||
type="search"
|
||||
name="search"
|
||||
className={`block w-full py-2 pl-10 pr-3 sm:text-sm bg-white dark:bg-vulcan-300 border border-gray-300 dark:border-vulcan-100 text-vulcan-500 dark:text-whisper-500 placeholder-gray-400 dark:placeholder-whisper-800 focus:outline-none`}
|
||||
placeholder="Search"
|
||||
value={value}
|
||||
autoFocus={true}
|
||||
onChange={handleChange}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
44
src/pagesView/components/Sorting.tsx
Normal file
44
src/pagesView/components/Sorting.tsx
Normal file
@@ -0,0 +1,44 @@
|
||||
import { Menu, Transition } from '@headlessui/react';
|
||||
import * as React from 'react';
|
||||
import { SortOption } from '../constants/SortOption';
|
||||
import { ChevronDownIcon } from '@heroicons/react/solid';
|
||||
import { Fragment } from 'react';
|
||||
import { MenuItem } from './MenuItem';
|
||||
import { MenuItems } from './MenuItems';
|
||||
import { MenuButton } from './MenuButton';
|
||||
|
||||
export interface ISortingProps {
|
||||
currentSorting: SortOption;
|
||||
|
||||
switchSorting: (sortId: SortOption) => void;
|
||||
}
|
||||
|
||||
export const sortOptions = [
|
||||
{ name: "Last modified", id: SortOption.LastModified },
|
||||
{ name: "By filename (asc)", id: SortOption.FileNameAsc },
|
||||
{ name: "By filename (desc)", id: SortOption.FileNameDesc },
|
||||
];
|
||||
|
||||
export const Sorting: React.FunctionComponent<ISortingProps> = ({currentSorting, switchSorting}: React.PropsWithChildren<ISortingProps>) => {
|
||||
|
||||
const crntSort = sortOptions.find(x => x.id === currentSorting);
|
||||
|
||||
return (
|
||||
<div className="flex items-center ml-6">
|
||||
<Menu as="div" className="relative z-10 inline-block text-left">
|
||||
<MenuButton label={`Sort by`} title={crntSort?.name || ""} />
|
||||
|
||||
<MenuItems>
|
||||
{sortOptions.map((option) => (
|
||||
<MenuItem
|
||||
key={option.id}
|
||||
title={option.name}
|
||||
value={option.id}
|
||||
isCurrent={option.id === currentSorting}
|
||||
onClick={switchSorting} />
|
||||
))}
|
||||
</MenuItems>
|
||||
</Menu>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
11
src/pagesView/components/Spinner.tsx
Normal file
11
src/pagesView/components/Spinner.tsx
Normal file
@@ -0,0 +1,11 @@
|
||||
import * as React from 'react';
|
||||
|
||||
export interface ISpinnerProps {}
|
||||
|
||||
export const Spinner: React.FunctionComponent<ISpinnerProps> = (props: React.PropsWithChildren<ISpinnerProps>) => {
|
||||
return (
|
||||
<div className={`fixed top-0 left-0 right-0 bottom-0 w-full h-full flex flex-wrap items-center justify-center bg-white bg-opacity-10 z-50`}>
|
||||
<div className="loader ease-linear rounded-full border-8 border-t-8 border-gray-50 h-32 w-32" />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
44
src/pagesView/components/Startup.tsx
Normal file
44
src/pagesView/components/Startup.tsx
Normal file
@@ -0,0 +1,44 @@
|
||||
import * as React from 'react';
|
||||
import { SETTINGS_DASHBOARD_OPENONSTART } from '../../constants';
|
||||
import { MessageHelper } from '../../helpers/MessageHelper';
|
||||
import { DashboardMessage } from '../DashboardMessage';
|
||||
import { Settings } from '../models/Settings';
|
||||
|
||||
export interface IStartupProps {
|
||||
settings: Settings;
|
||||
}
|
||||
|
||||
export const Startup: React.FunctionComponent<IStartupProps> = ({settings}: React.PropsWithChildren<IStartupProps>) => {
|
||||
const [isChecked, setIsChecked] = React.useState(false);
|
||||
|
||||
const onChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
setIsChecked(e.target.checked);
|
||||
MessageHelper.sendMessage(DashboardMessage.updateSetting, { name: SETTINGS_DASHBOARD_OPENONSTART, value: e.target.checked });
|
||||
};
|
||||
|
||||
React.useEffect(() => {
|
||||
console.log(`openOnStart`, settings.openOnStart);
|
||||
setIsChecked(!!settings.openOnStart);
|
||||
}, [settings?.openOnStart]);
|
||||
|
||||
return (
|
||||
<div className={`relative flex items-start`}>
|
||||
<div className="flex items-center h-5">
|
||||
<input
|
||||
id="startup"
|
||||
aria-describedby="startup-description"
|
||||
name="startup"
|
||||
type="checkbox"
|
||||
checked={isChecked}
|
||||
onChange={onChange}
|
||||
className="focus:outline-none focus:ring-teal-500 h-4 w-4 text-teal-600 border-gray-300 dark:border-vulcan-50 rounded"
|
||||
/>
|
||||
</div>
|
||||
<div className="ml-2 text-sm">
|
||||
<label id="startup-description" htmlFor="startup" className="font-medium text-vulcan-50 dark:text-whisper-900">
|
||||
Open on startup?
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
11
src/pagesView/components/Status.tsx
Normal file
11
src/pagesView/components/Status.tsx
Normal file
@@ -0,0 +1,11 @@
|
||||
import * as React from 'react';
|
||||
|
||||
export interface IStatusProps {
|
||||
draft: boolean;
|
||||
}
|
||||
|
||||
export const Status: React.FunctionComponent<IStatusProps> = ({draft}: React.PropsWithChildren<IStatusProps>) => {
|
||||
return (
|
||||
<span className={`inline-block px-2 py-1 leading-none rounded-full font-semibold uppercase tracking-wide text-xs text-whisper-200 dark:text-vulcan-500 ${draft ? "bg-red-500" : "bg-teal-500"}`}>{draft ? "Draft" : "Published"}</span>
|
||||
);
|
||||
};
|
||||
5
src/pagesView/constants/SortOption.ts
Normal file
5
src/pagesView/constants/SortOption.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export enum SortOption {
|
||||
LastModified = 1,
|
||||
FileNameAsc,
|
||||
FileNameDesc
|
||||
}
|
||||
5
src/pagesView/constants/Tab.ts
Normal file
5
src/pagesView/constants/Tab.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export enum Tab {
|
||||
All = 'all',
|
||||
Published = 'published',
|
||||
Draft = 'draft',
|
||||
};
|
||||
44
src/pagesView/hooks/useMessages.tsx
Normal file
44
src/pagesView/hooks/useMessages.tsx
Normal file
@@ -0,0 +1,44 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { MessageHelper } from '../../helpers/MessageHelper';
|
||||
import { ContentFolder } from '../../models';
|
||||
import { DashboardCommand } from '../DashboardCommand';
|
||||
import { DashboardMessage } from '../DashboardMessage';
|
||||
import { Page } from '../models/Page';
|
||||
import { Settings } from '../models/Settings';
|
||||
|
||||
const vscode = MessageHelper.getVsCodeAPI();
|
||||
|
||||
export default function useMessages(options?: any) {
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
const [pages, setPages] = useState<Page[]>([]);
|
||||
const [settings, setSettings] = useState<Settings>({} as any);
|
||||
|
||||
window.addEventListener('message', event => {
|
||||
const message = event.data;
|
||||
|
||||
switch (message.command) {
|
||||
case DashboardCommand.loading:
|
||||
setLoading(message.data);
|
||||
break;
|
||||
case DashboardCommand.settings:
|
||||
setSettings(message.data);
|
||||
break;
|
||||
case DashboardCommand.pages:
|
||||
setPages(message.data);
|
||||
setLoading(false);
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
setLoading(true);
|
||||
vscode.postMessage({ command: DashboardMessage.getTheme });
|
||||
vscode.postMessage({ command: DashboardMessage.getData });
|
||||
}, ['']);
|
||||
|
||||
return {
|
||||
loading,
|
||||
pages,
|
||||
settings
|
||||
};
|
||||
}
|
||||
68
src/pagesView/hooks/usePages.tsx
Normal file
68
src/pagesView/hooks/usePages.tsx
Normal file
@@ -0,0 +1,68 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { SortOption } from '../constants/SortOption';
|
||||
import { Tab } from '../constants/Tab';
|
||||
import { Page } from '../models/Page';
|
||||
import Fuse from 'fuse.js';
|
||||
|
||||
const fuseOptions: Fuse.IFuseOptions<Page> = {
|
||||
keys: [
|
||||
"title",
|
||||
"slug",
|
||||
"description",
|
||||
"fmFileName"
|
||||
]
|
||||
};
|
||||
|
||||
export default function usePages(pages: Page[], tab: Tab, sorting: SortOption, group: string | null, search: string | null, tag: string | null, category: string | null) {
|
||||
const [ pageItems, setPageItems ] = useState<Page[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
// Check if search needs to be performed
|
||||
let searchedPages = pages;
|
||||
if (search) {
|
||||
const fuse = new Fuse(pages, fuseOptions);
|
||||
const results = fuse.search(search);
|
||||
searchedPages = results.map(page => page.item);
|
||||
}
|
||||
|
||||
// Filter the pages
|
||||
let pagesToShow = searchedPages;
|
||||
if (tab === Tab.Published) {
|
||||
pagesToShow = searchedPages.filter(page => !page.draft);
|
||||
} else if (tab === Tab.Draft) {
|
||||
pagesToShow = searchedPages.filter(page => !!page.draft);
|
||||
} else {
|
||||
pagesToShow = searchedPages;
|
||||
}
|
||||
|
||||
// Sort the pages
|
||||
let pagesSorted = pagesToShow;
|
||||
if (sorting === SortOption.FileNameAsc) {
|
||||
pagesSorted = pagesToShow.sort((a, b) => a.fmFileName.toLowerCase().localeCompare(b.fmFileName.toLowerCase()));
|
||||
} else if (sorting === SortOption.FileNameDesc) {
|
||||
pagesSorted = pagesToShow.sort((a, b) => b.fmFileName.toLowerCase().localeCompare(a.fmFileName.toLowerCase()));
|
||||
} else {
|
||||
pagesSorted = pagesToShow.sort((a, b) => b.fmModified - a.fmModified);
|
||||
}
|
||||
|
||||
if (group) {
|
||||
pagesSorted = pagesSorted.filter(page => page.fmGroup === group);
|
||||
}
|
||||
|
||||
// Filter by tag
|
||||
if (tag) {
|
||||
pagesSorted = pagesSorted.filter(page => page.tags && page.tags.includes(tag));
|
||||
}
|
||||
|
||||
// Filter by category
|
||||
if (category) {
|
||||
pagesSorted = pagesSorted.filter(page => page.categories && page.categories.includes(category));
|
||||
}
|
||||
|
||||
setPageItems(pagesSorted);
|
||||
}, [ pages, tab, sorting, group, search, tag, category ]);
|
||||
|
||||
return {
|
||||
pageItems
|
||||
};
|
||||
}
|
||||
14
src/pagesView/index.tsx
Normal file
14
src/pagesView/index.tsx
Normal file
@@ -0,0 +1,14 @@
|
||||
import * as React from "react";
|
||||
import { render } from "react-dom";
|
||||
import { Dashboard } from "./components/Dashboard";
|
||||
|
||||
import './styles.css';
|
||||
|
||||
declare const acquireVsCodeApi: <T = unknown>() => {
|
||||
getState: () => T;
|
||||
setState: (data: T) => void;
|
||||
postMessage: (msg: unknown) => void;
|
||||
};
|
||||
|
||||
const elm = document.querySelector("#app");
|
||||
render(<Dashboard />, elm);
|
||||
17
src/pagesView/models/Page.ts
Normal file
17
src/pagesView/models/Page.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { Uri } from "vscode";
|
||||
|
||||
export interface Page {
|
||||
fmGroup: string;
|
||||
fmFilePath: string;
|
||||
fmFileName: string;
|
||||
fmModified: number;
|
||||
|
||||
title: string;
|
||||
slug: string;
|
||||
date: string | Date;
|
||||
draft: string;
|
||||
description: string;
|
||||
|
||||
preview?: string;
|
||||
[prop: string]: any;
|
||||
}
|
||||
9
src/pagesView/models/Settings.ts
Normal file
9
src/pagesView/models/Settings.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { ContentFolder } from './../../models/ContentFolder';
|
||||
|
||||
export interface Settings {
|
||||
folders: ContentFolder[];
|
||||
initialized: boolean
|
||||
tags: string[];
|
||||
categories: string[];
|
||||
openOnStart: boolean | null;
|
||||
}
|
||||
19
src/pagesView/styles.css
Normal file
19
src/pagesView/styles.css
Normal file
@@ -0,0 +1,19 @@
|
||||
@import "tailwindcss/base";
|
||||
@import "tailwindcss/components";
|
||||
@import "tailwindcss/utilities";
|
||||
|
||||
|
||||
.loader {
|
||||
border-top-color: #15c2cb;
|
||||
animation: spinner 1.5s linear infinite;
|
||||
}
|
||||
|
||||
@-webkit-keyframes spinner {
|
||||
0% { -webkit-transform: rotate(0deg); }
|
||||
100% { -webkit-transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
@keyframes spinner {
|
||||
0% { transform: rotate(0deg); }
|
||||
100% { transform: rotate(360deg); }
|
||||
}
|
||||
@@ -24,4 +24,5 @@ export enum CommandToCode {
|
||||
updatePreviewUrl = "update-preview-url",
|
||||
openInEditor = "open-in-editor",
|
||||
updateMetadata = "update-metadata",
|
||||
openDashboard = "open-dashboard",
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import useMessages from './hooks/useMessages';
|
||||
import { TagType } from './TagType';
|
||||
import { FolderAndFiles } from './components/FolderAndFiles';
|
||||
import { Metadata } from './components/Metadata';
|
||||
import { SponsorMsg } from './components/SponsorMsg';
|
||||
|
||||
export interface IViewPanelProps {
|
||||
}
|
||||
@@ -51,6 +52,8 @@ export const ViewPanel: React.FunctionComponent<IViewPanelProps> = (props: React
|
||||
|
||||
<OtherActions settings={settings} isFile={true} />
|
||||
</div>
|
||||
|
||||
<SponsorMsg />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -1,13 +1,14 @@
|
||||
import * as React from 'react';
|
||||
import { FolderInfo, PanelSettings } from '../../models';
|
||||
import { CommandToCode } from '../CommandToCode';
|
||||
import { MessageHelper } from '../helper/MessageHelper';
|
||||
import { MessageHelper } from '../../helpers/MessageHelper';
|
||||
import { Collapsible } from './Collapsible';
|
||||
import { GlobalSettings } from './GlobalSettings';
|
||||
import { OtherActions } from './OtherActions';
|
||||
import { FileList } from './FileList';
|
||||
import { VsLabel } from './VscodeComponents';
|
||||
import { FolderAndFiles } from './FolderAndFiles';
|
||||
import { SponsorMsg } from './SponsorMsg';
|
||||
|
||||
export interface IBaseViewProps {
|
||||
settings: PanelSettings | undefined;
|
||||
@@ -16,6 +17,10 @@ export interface IBaseViewProps {
|
||||
|
||||
export const BaseView: React.FunctionComponent<IBaseViewProps> = ({settings, folderAndFiles}: React.PropsWithChildren<IBaseViewProps>) => {
|
||||
|
||||
const openDashboard = () => {
|
||||
MessageHelper.sendMessage(CommandToCode.openDashboard);
|
||||
};
|
||||
|
||||
const initProject = () => {
|
||||
MessageHelper.sendMessage(CommandToCode.initProject);
|
||||
};
|
||||
@@ -32,6 +37,7 @@ export const BaseView: React.FunctionComponent<IBaseViewProps> = ({settings, fol
|
||||
|
||||
<Collapsible id={`base_actions`} title="Actions">
|
||||
<div className={`base__actions`}>
|
||||
<button onClick={openDashboard}>Open dashboard</button>
|
||||
<button onClick={initProject} disabled={settings?.isInitialized}>Initialize project</button>
|
||||
<button onClick={createContent} disabled={!settings?.isInitialized}>Create new content</button>
|
||||
</div>
|
||||
@@ -41,6 +47,8 @@ export const BaseView: React.FunctionComponent<IBaseViewProps> = ({settings, fol
|
||||
|
||||
<OtherActions settings={settings} isFile={false} isBase />
|
||||
</div>
|
||||
|
||||
<SponsorMsg />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as React from 'react';
|
||||
import { CommandToCode } from '../CommandToCode';
|
||||
import { MessageHelper } from '../helper/MessageHelper';
|
||||
import { MessageHelper } from '../../helpers/MessageHelper';
|
||||
import { ActionButton } from './ActionButton';
|
||||
|
||||
export interface ICustomScriptProps {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as React from 'react';
|
||||
import { CommandToCode } from '../CommandToCode';
|
||||
import { MessageHelper } from '../helper/MessageHelper';
|
||||
import { MessageHelper } from '../../helpers/MessageHelper';
|
||||
import { ActionButton } from './ActionButton';
|
||||
|
||||
export interface IDateActionProps {}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as React from 'react';
|
||||
import { FileInfo } from '../../models';
|
||||
import { CommandToCode } from '../CommandToCode';
|
||||
import { MessageHelper } from '../helper/MessageHelper';
|
||||
import { MessageHelper } from '../../helpers/MessageHelper';
|
||||
import { FileIcon } from './Icons/FileIcon';
|
||||
import { MarkdownIcon } from './Icons/MarkdownIcon';
|
||||
import { VsLabel } from './VscodeComponents';
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import * as React from 'react';
|
||||
import { PanelSettings } from '../../models';
|
||||
import { CommandToCode } from '../CommandToCode';
|
||||
import { MessageHelper } from '../helper/MessageHelper';
|
||||
import { useDebounce } from '../hooks/useDebounce';
|
||||
import { MessageHelper } from '../../helpers/MessageHelper';
|
||||
import { useDebounce } from '../../hooks/useDebounce';
|
||||
import { Collapsible } from './Collapsible';
|
||||
import { VsCheckbox, VsLabel } from './VscodeComponents';
|
||||
|
||||
|
||||
13
src/viewpanel/components/Icons/HeartIcon.tsx
Normal file
13
src/viewpanel/components/Icons/HeartIcon.tsx
Normal file
@@ -0,0 +1,13 @@
|
||||
import * as React from 'react';
|
||||
|
||||
export interface IHeartIconProps {
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export const HeartIcon: React.FunctionComponent<IHeartIconProps> = ({className}: React.PropsWithChildren<IHeartIconProps>) => {
|
||||
return (
|
||||
<svg xmlns="http://www.w3.org/2000/svg" className={`${className || ""}`} fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z" />
|
||||
</svg>
|
||||
);
|
||||
};
|
||||
@@ -1,9 +1,11 @@
|
||||
import * as React from 'react';
|
||||
|
||||
export interface IMarkdownIconProps {}
|
||||
export interface IMarkdownIconProps {
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export const MarkdownIcon: React.FunctionComponent<IMarkdownIconProps> = (props: React.PropsWithChildren<IMarkdownIconProps>) => {
|
||||
export const MarkdownIcon: React.FunctionComponent<IMarkdownIconProps> = ({className}: React.PropsWithChildren<IMarkdownIconProps>) => {
|
||||
return (
|
||||
<svg viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" fill="currentColor"><path d="M6.345 5h2.1v6.533H6.993l.055-5.31-1.774 5.31H4.072l-1.805-5.31c.04.644.06 5.31.06 5.31H1V5h2.156s1.528 4.493 1.577 4.807L6.345 5zm6.71 3.617v-3.5H11.11v3.5H9.166l2.917 2.916L15 8.617h-1.945z"/></svg>
|
||||
<svg className={className || ""} viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" fill="currentColor"><path d="M6.345 5h2.1v6.533H6.993l.055-5.31-1.774 5.31H4.072l-1.805-5.31c.04.644.06 5.31.06 5.31H1V5h2.156s1.528 4.493 1.577 4.807L6.345 5zm6.71 3.617v-3.5H11.11v3.5H9.166l2.917 2.916L15 8.617h-1.945z"/></svg>
|
||||
);
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as React from 'react';
|
||||
import { PanelSettings } from '../../models';
|
||||
import { CommandToCode } from '../CommandToCode';
|
||||
import { MessageHelper } from '../helper/MessageHelper';
|
||||
import { MessageHelper } from '../../helpers/MessageHelper';
|
||||
import { TagType } from '../TagType';
|
||||
import { Collapsible } from './Collapsible';
|
||||
import { Toggle } from './Fields/Toggle';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as React from 'react';
|
||||
import { PanelSettings } from '../../models';
|
||||
import { CommandToCode } from '../CommandToCode';
|
||||
import { MessageHelper } from '../helper/MessageHelper';
|
||||
import { MessageHelper } from '../../helpers/MessageHelper';
|
||||
import { Collapsible } from './Collapsible';
|
||||
import { BugIcon } from './Icons/BugIcon';
|
||||
import { CenterIcon } from './Icons/CenterIcon';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as React from 'react';
|
||||
import { MessageHelper } from '../../helpers/MessageHelper';
|
||||
import { CommandToCode } from '../CommandToCode';
|
||||
import { MessageHelper } from '../helper/MessageHelper';
|
||||
import { ActionButton } from './ActionButton';
|
||||
|
||||
export interface IPreviewProps {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
|
||||
|
||||
import * as React from 'react';
|
||||
import { MessageHelper } from '../../helpers/MessageHelper';
|
||||
import { CommandToCode } from '../CommandToCode';
|
||||
import { MessageHelper } from '../helper/MessageHelper';
|
||||
import { ActionButton } from './ActionButton';
|
||||
|
||||
export interface IPublishActionProps {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import * as React from 'react';
|
||||
import { MessageHelper } from '../../helpers/MessageHelper';
|
||||
import { SlugHelper } from '../../helpers/SlugHelper';
|
||||
import { Slug } from '../../models/PanelSettings';
|
||||
import { CommandToCode } from '../CommandToCode';
|
||||
import { MessageHelper } from '../helper/MessageHelper';
|
||||
import { ActionButton } from './ActionButton';
|
||||
|
||||
export interface ISlugActionProps {
|
||||
|
||||
14
src/viewpanel/components/SponsorMsg.tsx
Normal file
14
src/viewpanel/components/SponsorMsg.tsx
Normal file
@@ -0,0 +1,14 @@
|
||||
import * as React from 'react';
|
||||
import { HeartIcon } from './Icons/HeartIcon';
|
||||
|
||||
export interface ISponsorMsgProps {}
|
||||
|
||||
export const SponsorMsg: React.FunctionComponent<ISponsorMsgProps> = (props: React.PropsWithChildren<ISponsorMsgProps>) => {
|
||||
return (
|
||||
<p className={`sponsor`}>
|
||||
<a href="https://github.com/sponsors/estruyf" title="Sponsor Front Matter">
|
||||
<span>Sponsor</span> <HeartIcon className={`h-5 w-5 mr-2`} /> <span>FrontMatter</span>
|
||||
</a>
|
||||
</p>
|
||||
);
|
||||
};
|
||||
@@ -3,10 +3,10 @@ import { Tags } from './Tags';
|
||||
import { usePrevious } from '../hooks/usePrevious';
|
||||
import { CommandToCode } from '../CommandToCode';
|
||||
import { TagType } from '../TagType';
|
||||
import { MessageHelper } from '../helper/MessageHelper';
|
||||
import Downshift from 'downshift';
|
||||
import { AddIcon } from './Icons/AddIcon';
|
||||
import { VsLabel } from './VscodeComponents';
|
||||
import { MessageHelper } from '../../helpers/MessageHelper';
|
||||
|
||||
export interface ITagPickerProps {
|
||||
type: string;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { MessageHelper } from '../../helpers/MessageHelper';
|
||||
import { FolderInfo, PanelSettings } from '../../models/PanelSettings';
|
||||
import { Command } from '../Command';
|
||||
import { CommandToCode } from '../CommandToCode';
|
||||
import { MessageHelper } from '../helper/MessageHelper';
|
||||
import { TagType } from '../TagType';
|
||||
|
||||
const vscode = MessageHelper.getVsCodeAPI();
|
||||
|
||||
@@ -18,7 +18,10 @@ import { Notifications } from '../helpers/Notifications';
|
||||
import { COMMAND_NAME } from '../constants/Extension';
|
||||
import { Folders } from '../commands/Folders';
|
||||
import { Preview } from '../commands/Preview';
|
||||
import { getNonce } from '../helpers/getNonce';
|
||||
import { openFileInEditor } from '../helpers/openFileInEditor';
|
||||
|
||||
const FILE_LIMIT = 10;
|
||||
|
||||
export class ExplorerView implements WebviewViewProvider, Disposable {
|
||||
public static readonly viewType = "frontMatter.explorer";
|
||||
@@ -166,11 +169,14 @@ export class ExplorerView implements WebviewViewProvider, Disposable {
|
||||
case CommandToCode.openPreview:
|
||||
await commands.executeCommand(COMMAND_NAME.preview);
|
||||
break;
|
||||
case CommandToCode.openDashboard:
|
||||
await commands.executeCommand(COMMAND_NAME.dashboard);
|
||||
break;
|
||||
case CommandToCode.updatePreviewUrl:
|
||||
this.updatePreviewUrl(msg.data || "");
|
||||
break;
|
||||
case CommandToCode.openInEditor:
|
||||
this.openFileInEditor(msg.data);
|
||||
openFileInEditor(msg.data);
|
||||
break;
|
||||
case CommandToCode.updateMetadata:
|
||||
this.updateMetadata(msg.data);
|
||||
@@ -253,20 +259,6 @@ export class ExplorerView implements WebviewViewProvider, Disposable {
|
||||
ArticleHelper.update(editor, article);
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the file via its path
|
||||
*/
|
||||
private async openFileInEditor(filePath: string) {
|
||||
if (filePath) {
|
||||
try {
|
||||
const doc = await workspace.openTextDocument(Uri.file(filePath));
|
||||
await window.showTextDocument(doc, 1, false);
|
||||
} catch (e) {
|
||||
Notifications.error(`Couldn't open the file.`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a custom script
|
||||
* @param msg
|
||||
@@ -348,7 +340,7 @@ export class ExplorerView implements WebviewViewProvider, Disposable {
|
||||
public async getFoldersAndFiles() {
|
||||
this.postWebviewMessage({
|
||||
command: Command.folderInfo,
|
||||
data: await Folders.getInfo() || null
|
||||
data: await Folders.getInfo(FILE_LIMIT) || null
|
||||
});
|
||||
}
|
||||
|
||||
@@ -527,19 +519,7 @@ export class ExplorerView implements WebviewViewProvider, Disposable {
|
||||
* @param msg
|
||||
*/
|
||||
private postWebviewMessage(msg: { command: Command, data?: any }) {
|
||||
this.panel!.webview.postMessage(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a unique nonce
|
||||
*/
|
||||
private getNonce() {
|
||||
let text = '';
|
||||
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||
for (let i = 0; i < 32; i++) {
|
||||
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
||||
}
|
||||
return text;
|
||||
this.panel?.webview?.postMessage(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -552,7 +532,7 @@ export class ExplorerView implements WebviewViewProvider, Disposable {
|
||||
const stylesUri = webView.asWebviewUri(Uri.joinPath(this.extPath, 'assets/media', 'styles.css'));
|
||||
const scriptUri = webView.asWebviewUri(Uri.joinPath(this.extPath, 'dist', 'viewpanel.js'));
|
||||
|
||||
const nonce = this.getNonce();
|
||||
const nonce = getNonce();
|
||||
|
||||
return `
|
||||
<!DOCTYPE html>
|
||||
|
||||
115
tailwind.config.js
Normal file
115
tailwind.config.js
Normal file
@@ -0,0 +1,115 @@
|
||||
const colors = require('tailwindcss/colors');
|
||||
|
||||
module.exports = {
|
||||
mode: 'jit',
|
||||
purge: ['./src/**/*.{js,jsx,ts,tsx}'],
|
||||
darkMode: 'class', // or 'media' or 'class'
|
||||
theme: {
|
||||
extend: {
|
||||
colors: {
|
||||
white: colors.white,
|
||||
gray: colors.trueGray,
|
||||
"red": {
|
||||
"50": "#ff7c7b",
|
||||
"100": "#ff7271",
|
||||
"200": "#ff6867",
|
||||
"300": "#ff5e5d",
|
||||
"400": "#ff5453",
|
||||
"500": "#fe4a49",
|
||||
"600": "#f4403f",
|
||||
"700": "#ea3635",
|
||||
"800": "#e02c2b",
|
||||
"900": "#d62221"
|
||||
},
|
||||
"blue": {
|
||||
"50": "#90dfff",
|
||||
"100": "#86d5ff",
|
||||
"200": "#7ccbff",
|
||||
"300": "#72c1ff",
|
||||
"400": "#68b7fc",
|
||||
"500": "#5eadf2",
|
||||
"600": "#54a3e8",
|
||||
"700": "#4a99de",
|
||||
"800": "#408fd4",
|
||||
"900": "#3685ca"
|
||||
},
|
||||
"teal": {
|
||||
"50": "#47f4fd",
|
||||
"100": "#3deaf3",
|
||||
"200": "#33e0e9",
|
||||
"300": "#29d6df",
|
||||
"400": "#1fccd5",
|
||||
"500": "#15c2cb",
|
||||
"600": "#0bb8c1",
|
||||
"700": "#01aeb7",
|
||||
"800": "#00a4ad",
|
||||
"900": "#009aa3"
|
||||
},
|
||||
"aqua": {
|
||||
"50": "#76ffff",
|
||||
"100": "#6cfffa",
|
||||
"200": "#62fff0",
|
||||
"300": "#58ffe6",
|
||||
"400": "#4effdc",
|
||||
"500": "#44ffd2",
|
||||
"600": "#3af5c8",
|
||||
"700": "#30ebbe",
|
||||
"800": "#26e1b4",
|
||||
"900": "#1cd7aa"
|
||||
},
|
||||
"yellow": {
|
||||
"50": "#ffff90",
|
||||
"100": "#ffff86",
|
||||
"200": "#ffff7c",
|
||||
"300": "#fff872",
|
||||
"400": "#ffee68",
|
||||
"500": "#ffe45e",
|
||||
"600": "#f5da54",
|
||||
"700": "#ebd04a",
|
||||
"800": "#e1c640",
|
||||
"900": "#d7bc36"
|
||||
},
|
||||
"whisper": {
|
||||
"50": "#ffffff",
|
||||
"100": "#ffffff",
|
||||
"200": "#ffffff",
|
||||
"300": "#ffffff",
|
||||
"400": "#fdf9ff",
|
||||
"500": "#f3eff5",
|
||||
"600": "#e9e5eb",
|
||||
"700": "#dfdbe1",
|
||||
"800": "#d5d1d7",
|
||||
"900": "#cbc7cd"
|
||||
},
|
||||
"vulcan": {
|
||||
"50": "#404551",
|
||||
"100": "#363b47",
|
||||
"200": "#2c313d",
|
||||
"300": "#222733",
|
||||
"400": "#181d29",
|
||||
"500": "#0e131f",
|
||||
"600": "#040915",
|
||||
"700": "#00000b",
|
||||
"800": "#000001",
|
||||
"900": "#000000"
|
||||
},
|
||||
"rose": {
|
||||
"50": "#ff73da",
|
||||
"100": "#ff69d0",
|
||||
"200": "#ff5fc6",
|
||||
"300": "#ff55bc",
|
||||
"400": "#fb4bb2",
|
||||
"500": "#f141a8",
|
||||
"600": "#e7379e",
|
||||
"700": "#dd2d94",
|
||||
"800": "#d3238a",
|
||||
"900": "#c91980"
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
variants: {
|
||||
extend: {},
|
||||
},
|
||||
plugins: [],
|
||||
}
|
||||
@@ -63,5 +63,37 @@ module.exports = [
|
||||
maxEntrypointSize: 400000,
|
||||
maxAssetSize: 400000
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'pagesView',
|
||||
target: 'web',
|
||||
entry: './src/pagesView/index.tsx',
|
||||
output: {
|
||||
path: path.resolve(__dirname, 'dist'),
|
||||
filename: 'pages.js'
|
||||
},
|
||||
devtool: 'source-map',
|
||||
resolve: {
|
||||
extensions: ['.ts', '.js', '.tsx', '.jsx']
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.(ts|tsx)$/,
|
||||
exclude: /node_modules/,
|
||||
use: [{
|
||||
loader: 'ts-loader'
|
||||
}]
|
||||
},
|
||||
{
|
||||
test: /\.css$/,
|
||||
use: ['style-loader', 'css-loader', 'postcss-loader']
|
||||
}
|
||||
]
|
||||
},
|
||||
performance: {
|
||||
maxEntrypointSize: 400000,
|
||||
maxAssetSize: 400000
|
||||
}
|
||||
}
|
||||
];
|
||||
Reference in New Issue
Block a user