From 2e36b4a2b08cdd8706233c659e6fef88a6d4d74f Mon Sep 17 00:00:00 2001 From: Christian Preston Date: Mon, 26 Feb 2024 11:08:40 -0500 Subject: [PATCH 1/6] feat: autogen section icons --- app/server/plugins/content.ts | 13 +++++++++++++ docs/1.guide/1.index.md | 4 ---- docs/1.guide/components.md | 4 ---- docs/2.config/1.index.md | 4 ---- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/app/server/plugins/content.ts b/app/server/plugins/content.ts index e637f5b..ff403be 100644 --- a/app/server/plugins/content.ts +++ b/app/server/plugins/content.ts @@ -5,6 +5,19 @@ export default defineNitroPlugin((nitroApp) => { return } + // A Set of common icons for the guide + const commonIcons = { + '/guide': 'ph:book-open-duotone', + '/guide/components': 'bxs:component', + '/config': 'ri:settings-3-line', + '/configuration': 'ri:settings-3-line', + } + + // Set the icon for the file if it is not already set + if (commonIcons?.[file._path] && !file.icon) { + file.icon = commonIcons[file._path] + } + // Remove first h1 from markdown files as it is added to front-matter as title if (file.body?.children?.[0]?.tag === 'h1') { const text = getTextContents(file.body.children[0].children) diff --git a/docs/1.guide/1.index.md b/docs/1.guide/1.index.md index 4ea7825..9beb9a7 100644 --- a/docs/1.guide/1.index.md +++ b/docs/1.guide/1.index.md @@ -1,7 +1,3 @@ ---- -icon: ph:book-open-duotone ---- - # Getting Started > [!IMPORTANT] diff --git a/docs/1.guide/components.md b/docs/1.guide/components.md index ad03025..b1739ed 100644 --- a/docs/1.guide/components.md +++ b/docs/1.guide/components.md @@ -1,7 +1,3 @@ ---- -icon: bxs:component ---- - # Components > Discover the components you can use in your markdown files. diff --git a/docs/2.config/1.index.md b/docs/2.config/1.index.md index 00cd075..5590be6 100644 --- a/docs/2.config/1.index.md +++ b/docs/2.config/1.index.md @@ -1,7 +1,3 @@ ---- -icon: ri:settings-3-line ---- - # Configuration ## Example From 95864f356c6f5b2d6f3ecba64b961b96330fc580 Mon Sep 17 00:00:00 2001 From: Christian Preston Date: Mon, 26 Feb 2024 11:12:11 -0500 Subject: [PATCH 2/6] chore: map more common icons --- app/server/plugins/content.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/server/plugins/content.ts b/app/server/plugins/content.ts index ff403be..a88ad19 100644 --- a/app/server/plugins/content.ts +++ b/app/server/plugins/content.ts @@ -11,6 +11,8 @@ export default defineNitroPlugin((nitroApp) => { '/guide/components': 'bxs:component', '/config': 'ri:settings-3-line', '/configuration': 'ri:settings-3-line', + '/examples': 'ph:code', + '/utils': 'ph:function-bold' } // Set the icon for the file if it is not already set From 5864f5598732aefdcb981e69b2973e4cd95991ec Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Mon, 26 Feb 2024 16:12:44 +0000 Subject: [PATCH 3/6] chore: apply automated updates --- app/server/plugins/content.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/server/plugins/content.ts b/app/server/plugins/content.ts index a88ad19..5bf9e3d 100644 --- a/app/server/plugins/content.ts +++ b/app/server/plugins/content.ts @@ -12,7 +12,7 @@ export default defineNitroPlugin((nitroApp) => { '/config': 'ri:settings-3-line', '/configuration': 'ri:settings-3-line', '/examples': 'ph:code', - '/utils': 'ph:function-bold' + '/utils': 'ph:function-bold', } // Set the icon for the file if it is not already set From 1315a6959a66b9afd71bf8ff25ad9973a755abde Mon Sep 17 00:00:00 2001 From: Christian Preston Date: Mon, 26 Feb 2024 11:55:25 -0500 Subject: [PATCH 4/6] chore: style/pref --- app/server/plugins/content.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/server/plugins/content.ts b/app/server/plugins/content.ts index a88ad19..3db04aa 100644 --- a/app/server/plugins/content.ts +++ b/app/server/plugins/content.ts @@ -16,7 +16,7 @@ export default defineNitroPlugin((nitroApp) => { } // Set the icon for the file if it is not already set - if (commonIcons?.[file._path] && !file.icon) { + if (!file.icon && commonIcons?.[file._path]) { file.icon = commonIcons[file._path] } From 666defbe3ee0688f755f4fa45971645432c5572b Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Mon, 4 Mar 2024 17:43:48 +0100 Subject: [PATCH 5/6] ignore ts issue --- app/server/plugins/content.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/server/plugins/content.ts b/app/server/plugins/content.ts index c78126e..a500f21 100644 --- a/app/server/plugins/content.ts +++ b/app/server/plugins/content.ts @@ -1,5 +1,5 @@ export default defineNitroPlugin((nitroApp) => { - nitroApp.hooks.hook('content:file:afterParse', (file) => { + nitroApp.hooks.hook('content:file:afterParse' as any, (file) => { // Filter out non-markdown files if (!file._id.endsWith('.md')) { return From 2a655a02cf47592b1f9bcadac67a160bf92c3e33 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Mon, 4 Mar 2024 17:48:44 +0100 Subject: [PATCH 6/6] refactor --- app/server/plugins/content.ts | 52 ++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/app/server/plugins/content.ts b/app/server/plugins/content.ts index a500f21..40394df 100644 --- a/app/server/plugins/content.ts +++ b/app/server/plugins/content.ts @@ -1,23 +1,13 @@ export default defineNitroPlugin((nitroApp) => { - nitroApp.hooks.hook('content:file:afterParse' as any, (file) => { + nitroApp.hooks.hook('content:file:afterParse' as any, async (file) => { // Filter out non-markdown files if (!file._id.endsWith('.md')) { return } - // A Set of common icons for the guide - const commonIcons = { - '/guide': 'ph:book-open-duotone', - '/guide/components': 'bxs:component', - '/config': 'ri:settings-3-line', - '/configuration': 'ri:settings-3-line', - '/examples': 'ph:code', - '/utils': 'ph:function-bold', - } - // Set the icon for the file if it is not already set - if (!file.icon && commonIcons?.[file._path]) { - file.icon = commonIcons[file._path] + if (!file.icon) { + file.icon = await resolveIcon(file._path) } // Remove first h1 from markdown files as it is added to front-matter as title @@ -65,3 +55,39 @@ function getTextContents(children) { }) .join('') } + +// A set of common icons +const commonIcons = [ + { + pattern: 'guide', + icon: 'ph:book-open-duotone', + }, + { + pattern: 'components', + icon: 'bxs:component', + }, + { + pattern: 'config', + icon: 'ri:settings-3-line', + }, + { + pattern: 'configuration', + icon: 'ri:settings-3-line', + }, + { + pattern: 'examples', + icon: 'ph:code', + }, + { + pattern: 'utils', + icon: 'ph:function-bold', + }, +] + +function resolveIcon(path: string) { + for (const icon of commonIcons) { + if (path.includes(icon.pattern)) { + return icon.icon + } + } +}