Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: autogen section icons #72

Merged
merged 7 commits into from Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 42 additions & 1 deletion app/server/plugins/content.ts
@@ -1,10 +1,15 @@
export default defineNitroPlugin((nitroApp) => {
nitroApp.hooks.hook('content:file:afterParse', (file) => {
nitroApp.hooks.hook('content:file:afterParse' as any, async (file) => {
// Filter out non-markdown files
if (!file._id.endsWith('.md')) {
return
}

// Set the icon for the file if it is not already set
if (!file.icon) {
file.icon = await resolveIcon(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)
Expand Down Expand Up @@ -50,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
}
}
}
4 changes: 0 additions & 4 deletions docs/1.guide/1.index.md
@@ -1,7 +1,3 @@
---
icon: ph:book-open-duotone
---

# Getting Started

> [!IMPORTANT]
Expand Down
4 changes: 0 additions & 4 deletions docs/1.guide/components.md
@@ -1,7 +1,3 @@
---
icon: bxs:component
---

# Components

> Discover the components you can use in your markdown files.
Expand Down
4 changes: 0 additions & 4 deletions docs/2.config/1.index.md
@@ -1,7 +1,3 @@
---
icon: ri:settings-3-line
---

# Configuration

## Example
Expand Down