Skip to content

Commit

Permalink
Merge pull request #23 from HiDeoo/hd-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
HiDeoo authored Feb 17, 2024
2 parents 0b20349 + 012f559 commit 081a2d4
Show file tree
Hide file tree
Showing 62 changed files with 2,519 additions and 2,318 deletions.
3 changes: 0 additions & 3 deletions .eslintrc.json

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:

- name: Generates TypeScript types
run: pnpm astro sync
working-directory: example
working-directory: docs

- name: Lint
run: pnpm lint
Expand Down
13 changes: 13 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"eslint.experimental.useFlatConfig": true,
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
"html",
"vue",
"markdown",
"astro"
]
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions example/README.md → docs/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div align="center">
<h1>starlight-blog 📰</h1>
<p>Astro integration for Starlight to add a blog to your documentation.</p>
<p>Starlight plugin to add a blog to your documentation.</p>
</div>

<div align="center">
Expand All @@ -13,9 +13,9 @@
<br />
</div>

## Example
## Documentation

Run the example locally using your favorite package manager, e.g. with [pnpm](https://pnpm.io):
Run the documentation locally using your favorite package manager, e.g. with [pnpm](https://pnpm.io):

```shell
pnpm run dev
Expand Down
47 changes: 47 additions & 0 deletions docs/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import starlight from '@astrojs/starlight'
import { defineConfig } from 'astro/config'
import starlightBlog from 'starlight-blog'

export default defineConfig({
integrations: [
starlight({
customCss: ['./src/styles/custom.css'],
editLink: {
baseUrl: 'https://github.com/HiDeoo/starlight-blog/edit/main/docs/',
},
plugins: [
starlightBlog({
title: 'Demo Blog',
authors: {
hideoo: {
name: 'HiDeoo',
title: 'Starlight Aficionado',
picture: '/hideoo.png',
url: 'https://hideoo.dev',
},
},
}),
],
sidebar: [
{
label: 'Start Here',
items: [
{ label: 'Getting Started', link: '/getting-started/' },
{ label: 'Configuration', link: '/configuration/' },
],
},
{
label: 'Guides',
items: [
{ label: 'Frontmatter', link: '/guides/frontmatter/' },
{ label: 'Authors', link: '/guides/authors/' },
],
},
],
social: {
github: 'https://github.com/HiDeoo/starlight-blog',
},
title: 'Starlight Blog',
}),
],
})
12 changes: 6 additions & 6 deletions example/package.json → docs/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "starlight-blog-example",
"name": "starlight-blog-docs",
"version": "0.4.0",
"license": "MIT",
"description": "Astro integration for Starlight to add a blog to your documentation.",
"description": "Starlight plugin to add a blog to your documentation.",
"author": "HiDeoo <[email protected]> (https://hideoo.dev)",
"type": "module",
"scripts": {
Expand All @@ -14,8 +14,8 @@
"lint": "prettier -c --cache . && eslint . --cache --max-warnings=0"
},
"dependencies": {
"@astrojs/starlight": "0.11.0",
"astro": "3.2.3",
"@astrojs/starlight": "0.19.0",
"astro": "4.2.7",
"sharp": "0.32.5",
"starlight-blog": "workspace:*"
},
Expand All @@ -27,10 +27,10 @@
"sideEffects": false,
"keywords": [
"starlight",
"plugin",
"blog",
"documentation",
"astro",
"astro-integration"
"astro"
],
"homepage": "https://github.com/HiDeoo/starlight-blog",
"repository": {
Expand Down
1 change: 1 addition & 0 deletions docs/public/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
8 changes: 8 additions & 0 deletions docs/src/content/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { docsSchema, i18nSchema } from '@astrojs/starlight/schema'
import { defineCollection } from 'astro:content'
import { blogSchema } from 'starlight-blog/schema'

export const collections = {
docs: defineCollection({ schema: docsSchema({ extend: blogSchema() }) }),
i18n: defineCollection({ type: 'data', schema: i18nSchema() }),
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
104 changes: 104 additions & 0 deletions docs/src/content/docs/configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
---
title: Configuration
description: An overview of all the configuration options supported by the Starlight Blog plugin.
---

The Starlight Blog plugin can be configured inside the `astro.config.mjs` configuration file of your project:

```js {11}
// astro.config.mjs
import starlight from '@astrojs/starlight'
import { defineConfig } from 'astro/config'
import starlightBlog from 'starlight-blog'

export default defineConfig({
integrations: [
starlight({
plugins: [
starlightBlog({
// Configuration options go here.
}),
],
title: 'My Docs',
}),
],
})
```

## Plugin configuration

The Starlight Blog plugin accepts the following configuration options:

### `title`

**Type:** `string`
**Default:** `'Blog'`

The title of the blog.

### `postCount`

**Type:** `number`
**Default:** `5`

The number of blog posts to display per page in the blog post list.

### `recentPostCount`

**Type:** `number`
**Default:** `10`

The number of recent blog posts to display in the blog sidebar.

### `authors`

**Type:** [`StarlightBlogAuthorsConfig`](#author-configuration)

A list of global authors for all blog posts or regular authors that can be referenced in individual blog posts.
Check the ["Authors" guide](/guides/authors) section for more informations.

## Author configuration

Global authors for all blog posts or regular authors that can be referenced in individual blog posts can be defined using the [`authors`](#authors) configuration option.
When a blog post frontmatter does not define an author, the global authors from the configuration will be used instead.
Check the ["Authors" guide](/guides/authors) for more informations.

```js {4-9}
// astro.config.mjs
starlightBlog({
authors: {
alice: {
// Author configuration for the `alice` author goes here.
},
bob: {
// Author configuration for the `bob` author goes here.
},
},
})
```

An author can be configured using the following options:

### `name` (required)

**Type:** `string`

The name of the author.

### `title`

**Type:** `string`

A title to display below the author's name.

### `url`

**Type:** `string`

A URL to link the author's name to.

### `picture`

**Type:** `string`

A URL or path to an image in the `public/` directory to display as the author's picture.
118 changes: 118 additions & 0 deletions docs/src/content/docs/getting-started.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
---
title: Getting Started
description: Learn how to add a blog to your documentation site using the Starlight Blog plugin.
---

import { Tabs, TabItem } from '@astrojs/starlight/components'

A [Starlight](https://starlight.astro.build) plugin to add a blog to your documentation site.

- Link to the blog in the header
- Post list with pagination
- Global and per-post authors
- Tags
- Custom sidebar with recent posts and tags

Check out the [demo](/blog/) for a preview of the blog.

## Prerequisites

You will need to have a Starlight website set up.
If you don't have one yet, you can follow the ["Getting Started"](https://starlight.astro.build/getting-started) guide in the Starlight docs to create one.

## Install the plugin

Starlight Blog is a Starlight [plugin](https://starlight.astro.build/reference/plugins/).
Install it using your favorite package manager:

<Tabs>
<TabItem label="npm">

```sh
npm install starlight-blog
```

</TabItem>
<TabItem label="pnpm">

```sh
pnpm add starlight-blog
```

</TabItem>
<TabItem label="Yarn">

```sh
yarn add starlight-blog
```

</TabItem>
<TabItem label="Bun">

```sh
bun add starlight-blog
```

</TabItem>
<TabItem label="ni">

```sh
ni starlight-blog
```

</TabItem>
</Tabs>

## Configure the plugin

The Starlight Blog plugin can be configured in your Starlight [configuration](https://starlight.astro.build/reference/configuration/#plugins) in the `astro.config.mjs` file.

```diff lang="js"
// astro.config.mjs
import starlight from '@astrojs/starlight'
import { defineConfig } from 'astro/config'
+import starlightBlog from 'starlight-blog'

export default defineConfig({
integrations: [
starlight({
+ plugins: [starlightBlog()],
title: 'My Docs',
}),
],
})
```

The Starlight Blog plugin behavior can be tweaked using various [configuration options](/configuration).

## Extend frontmatter schema

Extend Starlight's frontmatter default schema to add support for customizing individual blog posts using their frontmatter in the `src/content/config.ts` file:

```diff lang="ts" ins="{ extend: blogSchema() }"
// src/content/config.ts
import { defineCollection } from 'astro:content';
import { docsSchema, i18nSchema } from '@astrojs/starlight/schema';
+import { blogSchema } from 'starlight-blog/schema'

export const collections = {
docs: defineCollection({ schema: docsSchema({ extend: blogSchema() }) }),
i18n: defineCollection({ type: 'data', schema: i18nSchema() }),
};
```

## Create your first blog post

Create your first blog post by creating a `.md` or `.mdx` file in the `src/content/docs/blog/` directory:

```md
---
// src/content/docs/blog/my-first-blog-post.md
title: My first blog post
date: 2023-07-24
---

## Hello

Hello world!
```
Loading

0 comments on commit 081a2d4

Please sign in to comment.