mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-03-28 17:42:40 +01:00
#517 - Add contentTypes property to custom scripts
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
|
||||
### 🎨 Enhancements
|
||||
|
||||
- [#517](https://github.com/estruyf/vscode-front-matter/issues/517): Add `contentTypes` property to custom scripts to show/hide custom actions
|
||||
- [#638](https://github.com/estruyf/vscode-front-matter/issues/638): Add Hexo support for the `_drafts` folder
|
||||
- [#659](https://github.com/estruyf/vscode-front-matter/issues/659): Implement a filter for the taxonomy dashboard
|
||||
- [#662](https://github.com/estruyf/vscode-front-matter/issues/662): Always show the `all articles` tab with the page counter
|
||||
|
||||
21
package.json
21
package.json
@@ -580,6 +580,13 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"contentTypes": {
|
||||
"type": "array",
|
||||
"description": "%setting.frontMatter.custom.scripts.items.properties.contentTypes.description%",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
@@ -983,6 +990,20 @@
|
||||
"markdownDescription": "%setting.frontMatter.panel.freeform.markdownDescription%",
|
||||
"scope": "Panel"
|
||||
},
|
||||
"frontMatter.panel.actions.disabled": {
|
||||
"type": "array",
|
||||
"default": [],
|
||||
"markdownDescription": "%setting.frontMatter.panel.actions.disabeld.markdownDescription%",
|
||||
"enum": [
|
||||
"openDashboard",
|
||||
"createContent",
|
||||
"optimizeSlug",
|
||||
"preview",
|
||||
"openOnWebsite",
|
||||
"startStopServer",
|
||||
"customActions"
|
||||
]
|
||||
},
|
||||
"frontMatter.preview.host": {
|
||||
"type": "string",
|
||||
"default": "",
|
||||
|
||||
@@ -244,5 +244,6 @@
|
||||
"setting.frontMatter.website.host.markdownDescription": "Geben Sie die Host-URL Ihrer Website an. [Überprüfen Sie die Dokumente] (https://frontmatter.codes/docs/settings/overview#frontmatter.website.url)",
|
||||
"command.frontMatter.settings.refresh": "Aktualisieren Sie die Einstellungen für Frontmatter",
|
||||
"setting.frontMatter.config.dynamicFilePath.markdownDescription": "Geben Sie den Pfad zur dynamischen Konfigurationsdatei an (z. B. [[workspace]]/config.js). [Überprüfen Sie die Dokumente] (https://frontmatter.codes/docs/settings/overview#frontmatter.config.dynamicfilepath)",
|
||||
"setting.frontMatter.content.pageFolders.items.properties.disableCreation.description": "Deaktivieren Sie die Erstellung neuer Inhalte im Ordner."
|
||||
"setting.frontMatter.content.pageFolders.items.properties.disableCreation.description": "Deaktivieren Sie die Erstellung neuer Inhalte im Ordner.",
|
||||
"setting.frontMatter.custom.scripts.items.properties.contentTypes.description": "Definieren Sie die Inhaltstypen, für die das Skript verwendet werden soll. Wenn keine definiert sind, ist sie für alle Typen verfügbar."
|
||||
}
|
||||
@@ -245,5 +245,6 @@
|
||||
"setting.frontMatter.website.host.markdownDescription": "ウェブサイトのホスト URL を指定します。[ドキュメントをチェックイン](https://frontmatter.codes/docs/settings/overview#frontmatter.website.url)",
|
||||
"command.frontMatter.settings.refresh": "フロントマター設定の更新",
|
||||
"setting.frontMatter.config.dynamicFilePath.markdownDescription": "動的構成ファイルへのパスを指定します (例: [[ワークスペース]]/config.js)。[ドキュメントをチェックイン](https://frontmatter.codes/docs/settings/overview#frontmatter.config.dynamicfilepath)",
|
||||
"setting.frontMatter.content.pageFolders.items.properties.disableCreation.description": "フォルダー内の新しいコンテンツの作成を無効にします。"
|
||||
"setting.frontMatter.content.pageFolders.items.properties.disableCreation.description": "フォルダー内の新しいコンテンツの作成を無効にします。",
|
||||
"setting.frontMatter.custom.scripts.items.properties.contentTypes.description": "スクリプトを使用するコンテンツ タイプを定義します。何も定義されていない場合は、すべての型で使用できます。"
|
||||
}
|
||||
@@ -105,6 +105,7 @@
|
||||
"setting.frontMatter.custom.scripts.items.properties.hidden.description": "Hide the action from the UI",
|
||||
"setting.frontMatter.custom.scripts.items.properties.environments.items.properties.type.description": "The environment type for which the script needs to be used",
|
||||
"setting.frontMatter.custom.scripts.items.properties.environments.items.properties.script.description": "Path to the script to execute",
|
||||
"setting.frontMatter.custom.scripts.items.properties.contentTypes.description": "Define the content types for which the script will be used. If none are defined, it will be available to all types.",
|
||||
"setting.frontMatter.dashboard.content.pagination.markdownDescription": "Specify if you want to enable/disable pagination for your content. You can define your page number up to 52. Default items per page is `16`. Disabling the pagination can be done by setting it to `false`. [Check in the docs](https://frontmatter.codes/docs/settings/overview#frontmatter.dashboard.content.pagination)",
|
||||
"setting.frontMatter.dashboard.content.cardTags.markdownDescription": "Specify the name of the metadata field that will be used to show the tags on the content card. When empty or null, it will hide the tags from the card. [Check in the docs](https://frontmatter.codes/docs/settings/overview#frontmatter.dashboard.content.cardtags)",
|
||||
"setting.frontMatter.dashboard.content.card.fields.state.markdownDescription": "Specify if you want to show the state/draft status on the content card view. [Check in the docs](https://frontmatter.codes/docs/settings/overview#frontMatter.dashboard.content.card.fields.state)",
|
||||
|
||||
@@ -197,6 +197,7 @@ export interface CustomScript {
|
||||
command?: CommandType | string;
|
||||
hidden?: boolean;
|
||||
environments?: EnvironmentScript[];
|
||||
contentTypes?: string[];
|
||||
}
|
||||
|
||||
export type EnvironmentType = 'windows' | 'macos' | 'linux';
|
||||
|
||||
@@ -8,6 +8,7 @@ import { StartServerButton } from './StartServerButton';
|
||||
import * as l10n from '@vscode/l10n';
|
||||
import { LocalizationKey } from '../../localization';
|
||||
import { OpenOnWebsiteAction } from './Actions/OpenOnWebsiteAction';
|
||||
import useContentType from '../../hooks/useContentType';
|
||||
|
||||
export interface IActionsProps {
|
||||
metadata: any;
|
||||
@@ -18,6 +19,29 @@ const Actions: React.FunctionComponent<IActionsProps> = ({
|
||||
metadata,
|
||||
settings
|
||||
}: React.PropsWithChildren<IActionsProps>) => {
|
||||
const contentType = useContentType(settings, metadata);
|
||||
|
||||
const actions = React.useMemo(() => {
|
||||
let allActions: JSX.Element[] = [];
|
||||
let scripts = settings.scripts || [];
|
||||
|
||||
if (contentType?.name) {
|
||||
scripts = scripts.filter((script) => {
|
||||
if (script.contentTypes && script.contentTypes.length > 0) {
|
||||
return script.contentTypes.includes(contentType.name);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
allActions = scripts.map((value, idx) => (
|
||||
<CustomScript key={value?.title?.replace(/ /g, '') || idx} {...value} />
|
||||
))
|
||||
|
||||
return allActions;
|
||||
}, [settings.scripts, contentType]);
|
||||
|
||||
if (!metadata || Object.keys(metadata).length === 0 || !settings) {
|
||||
return null;
|
||||
}
|
||||
@@ -37,9 +61,7 @@ const Actions: React.FunctionComponent<IActionsProps> = ({
|
||||
<>
|
||||
<div className="divider py-4 w-full" style={{ height: `1px` }}></div>
|
||||
|
||||
{settings.scripts.map((value, idx) => (
|
||||
<CustomScript key={value?.title?.replace(/ /g, '') || idx} {...value} />
|
||||
))}
|
||||
{...actions}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user