Skip to content

Commit

Permalink
#517 - Add contentTypes property to custom scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
estruyf committed Oct 4, 2023
1 parent 78bb853 commit e26028c
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,13 @@
}
}
}
},
"contentTypes": {
"type": "array",
"description": "%setting.frontMatter.custom.scripts.items.properties.contentTypes.description%",
"items": {
"type": "string"
}
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -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": "",
Expand Down
3 changes: 2 additions & 1 deletion package.nls.de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
3 changes: 2 additions & 1 deletion package.nls.ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "スクリプトを使用するコンテンツ タイプを定義します。何も定義されていない場合は、すべての型で使用できます。"
}
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
1 change: 1 addition & 0 deletions src/models/PanelSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ export interface CustomScript {
command?: CommandType | string;
hidden?: boolean;
environments?: EnvironmentScript[];
contentTypes?: string[];
}

export type EnvironmentType = 'windows' | 'macos' | 'linux';
Expand Down
28 changes: 25 additions & 3 deletions src/panelWebView/components/Actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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>
Expand Down

0 comments on commit e26028c

Please sign in to comment.