Skip to content

Commit

Permalink
feat: support front-matter in md docs
Browse files Browse the repository at this point in the history
  • Loading branch information
quentinderoubaix committed Mar 21, 2024
1 parent 6a6f82b commit df32859
Show file tree
Hide file tree
Showing 17 changed files with 111 additions and 20 deletions.
6 changes: 2 additions & 4 deletions demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@
"dev": {
"command": "vite dev",
"dependencies": [
"generate:doc",
"../angular/demo:dev",
"../react/demo:dev",
"../svelte/demo:dev"
"generate:doc"
],
"service": true
},
Expand Down Expand Up @@ -93,6 +90,7 @@
"bootstrap-icons": "^1.11.3",
"compare-versions": "^6.1.0",
"eslint-plugin-svelte": "^2.35.1",
"front-matter": "^4.0.2",
"prettier-plugin-svelte": "^3.2.2",
"shiki": "^1.2.0",
"svelte": "^4.2.12",
Expand Down
47 changes: 34 additions & 13 deletions demo/src/lib/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
import {componentsMetadata} from '../components-metadata';
import frontMatter from 'front-matter';

const validMdRegex = /^\d{2}-[a-zA-Z-]*\.md$/g;

const componentsSubMenu = [
{...componentsMetadata.Accordion, slug: 'components/accordion/', subpath: 'examples'},
{...componentsMetadata.Alert, slug: `components/alert/`, subpath: 'examples'},
{...componentsMetadata.Modal, slug: `components/modal/`, subpath: 'examples'},
{...componentsMetadata.Pagination, slug: `components/pagination/`, subpath: 'examples'},
{...componentsMetadata.Progressbar, slug: `components/progressbar/`, subpath: 'examples'},
{...componentsMetadata.Rating, slug: `components/rating/`, subpath: 'examples'},
{...componentsMetadata.Select, slug: `components/select/`, subpath: 'examples'},
{...componentsMetadata.Slider, slug: `components/slider/`, subpath: 'examples'},
{...componentsMetadata.Toast, slug: `components/toast/`, subpath: 'examples'},
{...componentsMetadata.Accordion, slug: 'components/accordion/', subpath: 'examples', attributes: {}},
{...componentsMetadata.Alert, slug: `components/alert/`, subpath: 'examples', attributes: {}},
{...componentsMetadata.Modal, slug: `components/modal/`, subpath: 'examples', attributes: {}},
{...componentsMetadata.Pagination, slug: `components/pagination/`, subpath: 'examples', attributes: {}},
{...componentsMetadata.Progressbar, slug: `components/progressbar/`, subpath: 'examples', attributes: {}},
{...componentsMetadata.Rating, slug: `components/rating/`, subpath: 'examples', attributes: {}},
{...componentsMetadata.Select, slug: `components/select/`, subpath: 'examples', attributes: {}},
{...componentsMetadata.Slider, slug: `components/slider/`, subpath: 'examples', attributes: {}},
{...componentsMetadata.Toast, slug: `components/toast/`, subpath: 'examples', attributes: {}},
];

const docFiles = import.meta.glob('../../../../docs/*/*.md', {query: '?raw', eager: true, import: 'default'});
const docs: {name: string; files: {slug: string; content?: string; title: string; subpath: string; status: string}[]}[] = [];
interface Doc {
name: string;
files: {
slug: string;
content?: string;
title: string;
subpath: string;
status: string;
attributes: Record<string, string>;
}[];
}

const docFiles = import.meta.glob<string>('../../../../docs/*/*.md', {query: '?raw', eager: true, import: 'default'});
const docs: Doc[] = [];
for (const [key, value] of Object.entries(docFiles)) {
const name = key.substring(20, key.indexOf('/', 20));
if (name === 'Components') {
Expand All @@ -35,12 +48,20 @@ for (const [key, value] of Object.entries(docFiles)) {
docs.push(docToPush);
}
const normalizedFileName = key.substring(key.indexOf('/', 20) + 1).slice(3, -3);

const fmData = frontMatter<Record<string, string>>(value);
for (const key of Object.keys(fmData.attributes)) {
if (typeof fmData.attributes[key] === 'string' && fmData.attributes[key]) {
fmData.attributes[key] = fmData.attributes[key].trim();
}
}
docToPush.files.push({
slug: `${name.toLowerCase()}/${normalizedFileName.toLowerCase()}`,
content: value as string,
content: fmData.body,
title: normalizedFileName.replace('-', ' '),
subpath: '',
status: '',
attributes: fmData.attributes,
});
}

Expand Down Expand Up @@ -93,5 +114,5 @@ export function retrieveMarkdown(slug: string, framework: string) {
}
}
}
return file ? {prev, next, content: preparseMarkdown(file.content!, framework)} : undefined;
return file ? {prev, next, content: preparseMarkdown(file.content!, framework), ...file.attributes} : undefined;
}
4 changes: 1 addition & 3 deletions demo/src/routes/docs/[framework]/[...slug]/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ export const load = async ({params}) => {
if (!file) error(404);
else {
return {
content: file.content,
prev: file.prev,
next: file.next,
slug: params.slug,
...file,
};
}
};
4 changes: 4 additions & 0 deletions docs/00-Getting-started/00-Introduction.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
since: 0.1.1
---

# Introduction

AgnosUI is a versatile widget library designed for various frameworks, providing a consistent user interface across platforms. Its core (also referred to as headless), written in pure TypeScript, serves as a foundation that can be utilized by any framework to generate a user interface.
Expand Down
4 changes: 4 additions & 0 deletions docs/00-Getting-started/01-Features.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
since: 0.1.1
---

# Features

## Agnostic core
Expand Down
4 changes: 4 additions & 0 deletions docs/00-Getting-started/02-Installation.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
since: 0.1.1
---

# Installation

## Prerequisites
Expand Down
4 changes: 4 additions & 0 deletions docs/01-Headless/00-Introduction.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
since: 0.1.1
---

# Introduction to Headless

A headless component is a design pattern where the component applies a separation of concerns between the logic (or "head") and the user interface (or "body").
Expand Down
4 changes: 4 additions & 0 deletions docs/01-Headless/01-Configuration.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
since: 0.1.1
---

# Configuration

## Overview
Expand Down
4 changes: 4 additions & 0 deletions docs/01-Headless/02-Slots.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
since: 0.1.1
---

# Slots

## What are Slots ?
Expand Down
4 changes: 4 additions & 0 deletions docs/01-Headless/03-Directives.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
since: 0.1.1
---

# Directives

## Overview
Expand Down
4 changes: 4 additions & 0 deletions docs/04-Services/00-Introduction.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
since: 0.1.1
---

# Introduction to Services

## Overview
Expand Down
4 changes: 4 additions & 0 deletions docs/04-Services/01-Focustrack.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
since: 0.1.1
---

# Focus track

## Motivation
Expand Down
4 changes: 4 additions & 0 deletions docs/04-Services/02-Floating-UI.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
since: 0.1.1
---

# Floating UI

## Service Overview
Expand Down
4 changes: 4 additions & 0 deletions docs/04-Services/03-Resize-Observer.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
since: 0.2.0
---

# Resize Observer

## Service Overview
Expand Down
4 changes: 4 additions & 0 deletions docs/04-Services/04-Transition.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
since: 0.2.0
---

# Transition

## Service Overview
Expand Down
23 changes: 23 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@
"wireit": {
"dev": {
"dependencies": [
"./angular/demo:dev",
"./react/demo:dev",
"./svelte/demo:dev",
"./demo:dev"
]
},
Expand Down

0 comments on commit df32859

Please sign in to comment.