### Create New SvelteKit App (Bash)
Source: https://github.com/svelteness/kit-docs/blob/main/packages/kit-docs/src/routes/docs/[...1]getting-started/[...2]quickstart/+page.md
Initialize a new SvelteKit project using the standard Svelte create command, navigate into the directory, and install dependencies.
```bash
npm create svelte mydocs
cd mydocs
npm i
```
--------------------------------
### Install KitDocs Dependencies (Bash)
Source: https://github.com/svelteness/kit-docs/blob/main/packages/kit-docs/src/routes/docs/[...1]getting-started/[...2]quickstart/+page.md
Install KitDocs and its required dependencies (iconify, unplugin-icons, clsx, shiki) as development dependencies using npm.
```bash
npm i @svelteness/kit-docs @iconify-json/ri unplugin-icons clsx shiki -D
```
--------------------------------
### Scaffold SvelteKit App with KitDocs (Bash)
Source: https://github.com/svelteness/kit-docs/blob/main/packages/kit-docs/src/routes/docs/[...1]getting-started/[...2]quickstart/+page.md
Use the KitDocs initializer to quickly create a new SvelteKit project with KitDocs boilerplate.
```bash
npm init @svelteness/kit-docs mydocs
```
--------------------------------
### Setting up Svelteness Kit Docs Development Environment (Shell)
Source: https://github.com/svelteness/kit-docs/blob/main/demo/README.md
Executes necessary commands to build the parent project, install dependencies, synchronize files, and start the development server for the Svelteness Kit documentation.
```sh
$ (cd ../; pnpm run build)
$ pnpm install
$ pnpm run sync
$ pnpm run dev
```
--------------------------------
### Example Sidebar Configuration Object (JS)
Source: https://github.com/svelteness/kit-docs/blob/main/packages/kit-docs/src/routes/docs/[...1]getting-started/[...2]quickstart/+page.md
Shows the structure of the JavaScript object used to define the sidebar navigation in Svelteness Kit Docs, including nested categories as keys and arrays of link objects with `title` and `slug` properties.
```js
const sidebar = {
links: {
'First Category': [
{ title: 'First Page', slug: '/docs/first-category/first-page' },
{ title: 'Second Page', slug: '/docs/first-category/second-page' },
],
'Second Category': [
// ...
],
},
};
```
--------------------------------
### Create KitDocs Meta Endpoint (JS)
Source: https://github.com/svelteness/kit-docs/blob/main/packages/kit-docs/src/routes/docs/[...1]getting-started/[...2]quickstart/+page.md
Create a SvelteKit server endpoint at `src/routes/kit-docs/[slug].meta/+server.js` that handles requests for markdown meta information using `createMetaRequestHandler`.
```js
import { createMetaRequestHandler } from '@svelteness/kit-docs/node';
export const GET = createMetaRequestHandler();
```
--------------------------------
### Create KitDocs Sidebar Endpoint (JS)
Source: https://github.com/svelteness/kit-docs/blob/main/packages/kit-docs/src/routes/docs/[...1]getting-started/[...2]quickstart/+page.md
Create a SvelteKit server endpoint at `src/routes/kit-docs/[dir].sidebar/+server.js` that handles requests for sidebar data using `createSidebarRequestHandler`.
```js
import { createSidebarRequestHandler } from '@svelteness/kit-docs/node';
export const GET = createSidebarRequestHandler();
```
--------------------------------
### Create KitDocs Root Layout (Svelte)
Source: https://github.com/svelteness/kit-docs/blob/main/packages/kit-docs/src/routes/docs/[...1]getting-started/[...2]quickstart/+page.md
Create the main SvelteKit layout file (`src/routes/+layout.svelte`) that imports and uses the `KitDocs` component, handles meta and sidebar data, and sets page title and description.
```svelte
{#key $page.url.pathname}
{#if title}
{title}
{/if}
{#if description}
{/if}
{/key}
```
--------------------------------
### Create First KitDocs Markdown File (Svelte/Markdown)
Source: https://github.com/svelteness/kit-docs/blob/main/packages/kit-docs/src/routes/docs/[...1]getting-started/[...2]quickstart/+page.md
Create a sample markdown file (`src/routes/docs/[...1]first-category/[...1]hello-world.md`) with frontmatter to demonstrate the basic structure of a KitDocs content file.
```svelte
---
description: My first markdown file.
---
```
--------------------------------
### Log Message in Svelte Markdown
Source: https://github.com/svelteness/kit-docs/blob/main/packages/kit-docs/src/routes/docs/[...1]getting-started/[...2]quickstart/+page.md
Demonstrates that markdown files are processed as Svelte components by including a script block that logs a message to the browser console.
```Svelte
```
--------------------------------
### Writable Store Usage (With Start/Stop Functions)
Source: https://github.com/svelteness/kit-docs/blob/main/demo/src/routes/docs/[...3]runtime/[...2]stores/+page.md
Example demonstrating the use of the optional start function, which is called on the first subscription, and the returned stop function, called on the last unsubscription.
```js
import { writable } from 'svelte/store';
const count = writable(0, () => {
console.log('got a subscriber');
return () => console.log('no more subscribers');
});
count.set(1); // does nothing
const unsubscribe = count.subscribe((value) => {
console.log(value);
}); // logs 'got a subscriber', then '1'
unsubscribe(); // logs 'no more subscribers'
```
--------------------------------
### Create KitDocs Root Layout Loader (JS)
Source: https://github.com/svelteness/kit-docs/blob/main/packages/kit-docs/src/routes/docs/[...1]getting-started/[...2]quickstart/+page.md
Create the SvelteKit layout load function (`src/routes/+layout.js`) that uses `createKitDocsLoader` to fetch meta and sidebar data for the layout, configuring sidebar paths.
```js
import { createKitDocsLoader } from '@svelteness/kit-docs';
export const prerender = true;
/** @type {import('./$types').LayoutLoad} */
export const load = createKitDocsLoader({
sidebar: {
'/': null,
'/docs': '/docs'
}
});
```
--------------------------------
### Configure SvelteKit for Markdown (JS)
Source: https://github.com/svelteness/kit-docs/blob/main/packages/kit-docs/src/routes/docs/[...1]getting-started/[...2]quickstart/+page.md
Modify the `svelte.config.js` file to include the `.md` file extension in the `extensions` array, allowing SvelteKit to process markdown files.
```js
import adapter from '@sveltejs/adapter-auto';
/** @type {import('@sveltejs/kit').Config} */
const config = {
extensions: ['.svelte', '.md'],
kit: {
adapter: adapter()
}
};
export default config;
```
--------------------------------
### Redirect Root Page in SvelteKit
Source: https://github.com/svelteness/kit-docs/blob/main/packages/kit-docs/src/routes/docs/[...1]getting-started/[...2]quickstart/+page.md
Shows how to create a redirect from the root path (/) to another page (/docs/first-category/first-page) using SvelteKit's `redirect` function in a `+page.js` file. The `prerender` export is set to true.
```JavaScript
import { redirect } from '@sveltejs/kit';
export const prerender = true;
/** @type {import('./$types').PageLoad} */
export function load() {
throw redirect(307, '/docs/first-category/first-page');
}
```
--------------------------------
### Configure Vite for KitDocs and Icons (JS)
Source: https://github.com/svelteness/kit-docs/blob/main/packages/kit-docs/src/routes/docs/[...1]getting-started/[...2]quickstart/+page.md
Update the `vite.config.js` file to add the `unplugin-icons` and `kitDocs` plugins to the Vite configuration, enabling icon processing and KitDocs features.
```js
import { sveltekit } from '@sveltejs/kit/vite';
import icons from 'unplugin-icons/vite';
import kitDocs from '@svelteness/kit-docs/node';
/** @type {import('vite').UserConfig} */
const config = {
plugins: [icons({ compiler: 'svelte' }), kitDocs(), sveltekit()]
};
export default config;
```
--------------------------------
### Add KitDocs Global TypeScript Types (TS)
Source: https://github.com/svelteness/kit-docs/blob/main/packages/kit-docs/src/routes/docs/[...1]getting-started/[...2]quickstart/+page.md
Include the KitDocs global TypeScript types reference in the `src/app.d.ts` file to provide type checking for KitDocs features.
```ts
///
///
// ...
```
--------------------------------
### Accessing KitDocs Metadata and Frontmatter Stores (Svelte)
Source: https://github.com/svelteness/kit-docs/blob/main/packages/kit-docs/src/routes/docs/[...1]getting-started/[...2]quickstart/+page.md
This Svelte script block demonstrates importing and accessing the `kitDocs` and `frontmatter` stores provided by `@svelteness/kit-docs`. These stores allow reactive access to the loaded Markdown metadata and frontmatter within Svelte components.
```Svelte
```
--------------------------------
### Override Meta Endpoint Slug Resolver
Source: https://github.com/svelteness/kit-docs/blob/main/packages/kit-docs/src/routes/docs/[...1]getting-started/[...2]quickstart/+page.md
Configures the `kit-docs/[slug].meta/+server.js` endpoint to use a custom function for resolving slugs to file paths. The example shows how to use the default `resolve` helper or provide an array of resolvers.
```JavaScript
import { createMetaRequestHandler } from '@svelteness/kit-docs/node';
export const GET = createMetaRequestHandler({
// map slug to absolute or relative file path to `routes` directory.
// returning `null` or `undefined` will fallback to default resolver.
// `resolve` helper will return default value.
resolve: (slug, { resolve }) => resolve(slug),
// you can provide an array and first to resolve will be accepted.
resolve: [(slug) => ``, null, undefined, false, async (slug) => null],
});
```
--------------------------------
### Configure Tailwind Content for Kit-Docs
Source: https://github.com/svelteness/kit-docs/blob/main/packages/kit-docs/src/routes/docs/[...1]getting-started/[...2]quickstart/+page.md
Updates the Tailwind CSS configuration file (`tailwind.config.cjs`) to include the paths for Svelte files and the kit-docs client components, ensuring Tailwind styles are applied correctly.
```JavaScript
module.exports = {
content: [
'./src/**/*.{html,svelte}',
'./node_modules/@svelteness/kit-docs/client/kit-docs/**/*.svelte',
],
};
```
--------------------------------
### Combine Slug Resolution and Meta Transformation
Source: https://github.com/svelteness/kit-docs/blob/main/packages/kit-docs/src/routes/docs/[...1]getting-started/[...2]quickstart/+page.md
Shows how to return a `transform` function directly from the `resolve` function within the `kit-docs/[slug].meta/+server.js` endpoint configuration. This allows applying specific transformations based on the resolved file.
```JavaScript
import { createMetaRequestHandler } from '@svelteness/kit-docs/node';
export const GET = createMetaRequestHandler({
resolve: (slug, { resolve }) => {
return {
file: resolve(slug),
// this can also be an array of transformers.
transform: ({ slug, filePath, meta }) => {
// ...
},
};
},
});
```
--------------------------------
### Creating KitDocs Loader with Simple Sidebar Config (Svelte)
Source: https://github.com/svelteness/kit-docs/blob/main/packages/kit-docs/src/routes/docs/[...1]getting-started/[...2]quickstart/+page.md
This Svelte script block shows how to use `createKitDocsLoader` to generate a SvelteKit `load` function. It configures the loader to build the sidebar from the specified directory path (`/docs`). This simplifies loading Markdown data into Svelte components.
```Svelte
```
--------------------------------
### Add Color Scheme Script (HTML)
Source: https://github.com/svelteness/kit-docs/blob/main/packages/kit-docs/src/routes/docs/[...2]default-layout/[...1]installation/+page.md
Adds a script to the `
` of `app.html` to handle color scheme detection and application based on local storage or system preference.
```html
```
--------------------------------
### Filter Files for Meta Endpoint
Source: https://github.com/svelteness/kit-docs/blob/main/packages/kit-docs/src/routes/docs/[...1]getting-started/[...2]quickstart/+page.md
Configures the `kit-docs/[slug].meta/+server.js` endpoint to include or exclude files based on Rollup filter patterns (`include` and `exclude`). Patterns are matched against file paths relative to `src/routes`.
```JavaScript
import { createMetaRequestHandler } from '@svelteness/kit-docs/node';
export const GET = createMetaRequestHandler({
// These are Rollup filter patterns.
// Filters match against file paths relative to `src/routes` dir.
// Paths are cleaned. No rest params `[...1]` or layout id `@...`.
include: /\.md/,
exclude: ['/docs/**/file.md', /some-regex/, '**/ignored-dir'],
});
```
--------------------------------
### Example Usage of Svelte Compiler Parse
Source: https://github.com/svelteness/kit-docs/blob/main/demo/src/routes/docs/[...5]compiler/[...2]parse/+page.md
An example demonstrating how to use the `svelte.parse` function. It requires the `svelte/compiler` module and calls `svelte.parse` with the source code and a filename option to get the component's AST.
```js
const svelte = require('svelte/compiler');
const ast = svelte.parse(source, { filename: 'App.svelte' });
```
--------------------------------
### Manually Loading KitDocs Meta and Sidebar Data (Svelte)
Source: https://github.com/svelteness/kit-docs/blob/main/packages/kit-docs/src/routes/docs/[...1]getting-started/[...2]quickstart/+page.md
This SvelteKit `load` function shows how to manually fetch Markdown metadata and sidebar data using `loadKitDocsMeta` and `loadKitDocsSidebar`. It retrieves meta for the current page and sidebar data for a specific path, returning them as props.
```Svelte
```
--------------------------------
### Implementing Copy Highlight Steps in JavaScript
Source: https://github.com/svelteness/kit-docs/blob/main/packages/kit-docs/src/routes/docs/[...3]markdown/[...2]extensions/+page.md
This example shows how to combine `copySteps` with line highlighting (`{1,3-5}`). Only the specified lines (1 and 3 through 5) will be highlighted and copied one by one when the user interacts with the copy button.
```js
const foo = 1;
function bar() {
// ...
}
```
--------------------------------
### Creating KitDocs Loader with Multi-Path Sidebar Config (Svelte)
Source: https://github.com/svelteness/kit-docs/blob/main/packages/kit-docs/src/routes/docs/[...1]getting-started/[...2]quickstart/+page.md
This Svelte script block demonstrates configuring `createKitDocsLoader` with a multi-path sidebar object. The loader will select the sidebar directory based on the current route path, allowing different sidebars for different sections of the site.
```Svelte
```
--------------------------------
### Using Global Svelte Components in Markdown
Source: https://github.com/svelteness/kit-docs/blob/main/packages/kit-docs/src/routes/docs/[...1]getting-started/[...2]quickstart/+page.md
This Markdown snippet shows two ways to use Svelte components made global via the `src/kit-docs` directory: as standard HTML-like tags and as markdown containers (`:::component-name`). It demonstrates passing attributes and slot content.
```Markdown
:::button propA="valueA"|propB=10
Default slot content here.
:::
:::button (tag=h1&slot=title)=Title
Default slot content here.
:::
```
--------------------------------
### Transform Meta Endpoint Data
Source: https://github.com/svelteness/kit-docs/blob/main/packages/kit-docs/src/routes/docs/[...1]getting-started/[...2]quickstart/+page.md
Demonstrates how to modify the meta data object returned by the `kit-docs/[slug].meta/+server.js` endpoint using a `transform` function. This allows customizing properties like title, description, frontmatter, and headers.
```JavaScript
import { createMetaRequestHandler } from '@svelteness/kit-docs/node';
export const GET = createMetaRequestHandler({
transform: ({ slug, filePath, meta, html, links }) => {
meta.title = '...';
meta.description = '...';
meta.frontmatter.prop = '...';
meta.headers = [
...meta.headers,
{ level: 2, title: 'Custom Heading', slug: '#custom-heading' },
// ...
];
},
// you can provide an array and they will all be called.
transform: [({ slug }) => {}, null, undefined, false, async () => {}],
});
```
--------------------------------
### Implementing Copy Steps in Bash
Source: https://github.com/svelteness/kit-docs/blob/main/packages/kit-docs/src/routes/docs/[...3]markdown/[...2]extensions/+page.md
This code block demonstrates how to use the `copySteps` option with a bash script. Each line will be highlighted and copied sequentially upon user interaction, guiding the user through a multi-step process.
```bash
npm create svelte docs
cd docs
npm i
```
--------------------------------
### Installing Svelte Static Adapter (Bash)
Source: https://github.com/svelteness/kit-docs/blob/main/packages/kit-docs/src/routes/docs/[...4]production/[...6]deploying/+page.md
Installs the static adapter for SvelteKit as a development dependency using npm. This adapter is required for generating static builds of the site.
```bash
npm i @sveltejs/adapter-static -D
```
--------------------------------
### Writable Store Basic Usage (Set and Update)
Source: https://github.com/svelteness/kit-docs/blob/main/demo/src/routes/docs/[...3]runtime/[...2]stores/+page.md
Example demonstrating the creation of a writable store and the usage of its subscribe, set, and update methods.
```js
import { writable } from 'svelte/store';
const count = writable(0);
count.subscribe((value) => {
console.log(value);
}); // logs '0'
count.set(1); // logs '1'
count.update((n) => n + 1); // logs '2'
```
--------------------------------
### Copy Font Files (Bash)
Source: https://github.com/svelteness/kit-docs/blob/main/packages/kit-docs/src/routes/docs/[...2]default-layout/[...1]installation/+page.md
Copies the theme font files from the installed package's `node_modules` directory to the project's `src/fonts` directory.
```bash
cp -R node_modules/@svelteness/kit-docs/client/fonts src/fonts
```
--------------------------------
### Markdown Input Example for Component Mapping
Source: https://github.com/svelteness/kit-docs/blob/main/packages/create-kit-docs/template-base/src/kit-docs/README.md
Provides the example Markdown syntax (`![]`, `>`, `!!!button`) that corresponds to the component mapping configuration shown in `svelte.config.js`, serving as the input for the transformation.
```markdown

> This is a blockquote.
!!!button
...
!!!
```
--------------------------------
### Handling Sidebar Requests in SvelteKit Server (JavaScript)
Source: https://github.com/svelteness/kit-docs/blob/main/packages/kit-docs/src/routes/docs/[...1]getting-started/[...2]quickstart/+page.md
This SvelteKit server handler demonstrates how to process incoming requests for sidebar data. It uses `paramToDir` to convert URL parameters into a directory path and `handleSidebarRequest` to fetch the sidebar data, optionally filtering results. It returns the sidebar data or null on error.
```JavaScript
import {
handleSidebarRequest,
paramToDir,
} from '@svelteness/kit-docs/node';
/** @type {import('@sveltejs/kit').RequestHandler} */
export function get({ params }) {
try {
const dir = paramToDir(params.dir);
const sidebar = await handleSidebarRequest(dir, {
filter: (id) => id.endsWith('.md')
});
return { body: sidebar };
} catch (e) {
// no-op
}
return { body: null };
}
```
--------------------------------
### Handling Meta Requests in SvelteKit Endpoint (JS)
Source: https://github.com/svelteness/kit-docs/blob/main/packages/kit-docs/src/routes/docs/[...1]getting-started/[...2]quickstart/+page.md
Demonstrates how to create a SvelteKit endpoint (`+server.js`) to handle meta requests using `@svelteness/kit-docs/node`. It shows how to extract the slug from parameters, call `handleMetaRequest` to parse the file, and return the extracted meta data in the response body.
```js
import {
handleMetaRequest,
paramToSlug,
} from '@svelteness/kit-docs/node';
/** @type {import('@sveltejs/kit').RequestHandler} */
export function get({ params }) {
try {
const slug = paramToSlug(params.slug);
const parserResult = await handleMetaRequest(slug);
return { body: parserResult.meta };
} catch (e) {
// no-op
}
return { body: null };
}
```
--------------------------------
### Configure Tailwind Content (JS)
Source: https://github.com/svelteness/kit-docs/blob/main/packages/kit-docs/src/routes/docs/[...2]default-layout/[...1]installation/+page.md
Adds the Svelteness Kit-Docs client files to the Tailwind CSS `content` configuration array to ensure utility classes from the library are included in the build.
```js
module.exports = {
content: ['./src/**/*.{html,svelte}', './node_modules/@svelteness/kit-docs/client/**/*.svelte'],
};
```
--------------------------------
### Svelte Output Example from Component Mapping
Source: https://github.com/svelteness/kit-docs/blob/main/packages/create-kit-docs/template-base/src/kit-docs/README.md
Shows the resulting Svelte code (``, `