Skip to content

Commit

Permalink
feat!: Starlight Links Validator is now a Starlight plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
HiDeoo committed Dec 11, 2023
1 parent a28748a commit 1d8ff99
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 59 deletions.
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div align="center">
<h1>starlight-links-validator 🦺</h1>
<p>Astro integration for Starlight to validate internal links.</p>
<p>Starlight plugin to validate internal links.</p>
</div>

<div align="center">
Expand Down
6 changes: 3 additions & 3 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "starlight-links-validator-docs",
"version": "0.4.2",
"license": "MIT",
"description": "Astro integration for Starlight to validate internal links.",
"description": "Starlight plugin to validate internal links.",
"author": "HiDeoo <[email protected]> (https://hideoo.dev)",
"type": "module",
"scripts": {
Expand All @@ -25,10 +25,10 @@
"sideEffects": false,
"keywords": [
"starlight",
"plugin",
"links",
"validation",
"astro",
"astro-integration"
"astro"
],
"homepage": "https://github.com/HiDeoo/starlight-links-validator",
"repository": {
Expand Down
34 changes: 19 additions & 15 deletions docs/src/content/docs/guides/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ import { Tabs, TabItem } from '@astrojs/starlight/components'

## Features

A [Starlight](https://starlight.astro.build) plugin to validate **_internal_** links in Markdown and MDX files.

- Validate internal links to other pages
- Validate internal links to anchors in other pages
- Validate internal links to anchors in the same page
- Ignore external links
- Run only during a production build

## Installation
## Install the plugin

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

<Tabs>
<TabItem label="npm">
Expand Down Expand Up @@ -54,20 +56,22 @@ ni starlight-links-validator
</TabItem>
</Tabs>

Update your [Astro configuration](https://docs.astro.build/en/guides/configuring-astro/#supported-config-file-types) to include the Starlight Links Validator integration **_before_** the Starlight integration:
## Add the plugin

The Starlight Links Validator plugin can be added to 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 starlightLinksValidator from 'starlight-links-validator'

export default defineConfig({
integrations: [
+ starlightLinksValidator(),
starlight({
title: 'My Docs',
}),
],
})
import starlight from '@astrojs/starlight'
import { defineConfig } from 'astro/config'
+import starlightLinksValidator from 'starlight-links-validator'

export default defineConfig({
integrations: [
starlight({
+ plugins: [starlightLinksValidator()],
title: 'My Docs',
}),
],
})
```
6 changes: 3 additions & 3 deletions docs/src/content/docs/index.mdx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
title: Starlight Links Validator
description: Astro integration for Starlight to validate internal links.
description: Starlight plugin to validate internal links.
head:
- tag: title
content: Starlight Links Validator
template: splash
editUrl: false
lastUpdated: false
hero:
tagline: Astro integration for Starlight to validate internal links.
tagline: Starlight plugin to validate internal links.
image:
html: '🦺'
actions:
Expand All @@ -23,7 +23,7 @@ import { Card, CardGrid } from '@astrojs/starlight/components'
## Next steps

<CardGrid stagger>
<Card title="Configure the integration" icon="setting">
<Card title="Configure the plugin" icon="setting">
Edit your config in `astro.config.mjs`.
</Card>
<Card title="Read the docs" icon="open-book">
Expand Down
2 changes: 1 addition & 1 deletion example/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div align="center">
<h1>starlight-links-validator 🦺</h1>
<p>Astro integration for Starlight to validate internal links.</p>
<p>Starlight plugin to validate internal links.</p>
</div>

<div align="center">
Expand Down
2 changes: 1 addition & 1 deletion example/astro.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import starlightLinksValidator from 'starlight-links-validator'

export default defineConfig({
integrations: [
starlightLinksValidator(),
starlight({
editLink: {
baseUrl: 'https://github.com/HiDeoo/starlight-links-validator/edit/main/example/',
},
plugins: [starlightLinksValidator()],
sidebar: [
{
label: 'Guides',
Expand Down
6 changes: 3 additions & 3 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "starlight-links-validator-example",
"version": "0.4.2",
"license": "MIT",
"description": "Astro integration for Starlight to validate internal links.",
"description": "Starlight plugin to validate internal links.",
"author": "HiDeoo <[email protected]> (https://hideoo.dev)",
"type": "module",
"scripts": {
Expand All @@ -26,10 +26,10 @@
"sideEffects": false,
"keywords": [
"starlight",
"plugin",
"links",
"validation",
"astro",
"astro-integration"
"astro"
],
"homepage": "https://github.com/HiDeoo/starlight-links-validator",
"repository": {
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "starlight-links-validator-monorepo",
"version": "0.4.2",
"license": "MIT",
"description": "Astro integration for Starlight to validate internal links.",
"description": "Starlight plugin to validate internal links.",
"author": "HiDeoo <[email protected]> (https://hideoo.dev)",
"type": "module",
"scripts": {
Expand All @@ -28,10 +28,10 @@
"sideEffects": false,
"keywords": [
"starlight",
"plugin",
"links",
"validation",
"astro",
"astro-integration"
"astro"
],
"homepage": "https://github.com/HiDeoo/starlight-links-validator",
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions packages/starlight-links-validator/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div align="center">
<h1>starlight-links-validator 🦺</h1>
<p>Astro integration for Starlight to validate internal links.</p>
<p>Starlight plugin to validate internal links.</p>
<p>
<a href="https://i.imgur.com/EgiTGeR.png" title="Screenshot of starlight-links-validator">
<img alt="Screenshot of starlight-links-validator" src="https://i.imgur.com/EgiTGeR.png" width="520" />
Expand All @@ -24,7 +24,7 @@ Want to get started immediately? Check out the [getting started guide](https://s

## Features

An [Astro](https://astro.build) integration for [Starlight](https://starlight.astro.build) Starlight to validate **_internal_** links in Markdown and MDX files.
A [Starlight](https://starlight.astro.build) plugin to validate **_internal_** links in Markdown and MDX files.

- Validate internal links to other pages
- Validate internal links to anchors in other pages
Expand Down
51 changes: 29 additions & 22 deletions packages/starlight-links-validator/index.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,42 @@
import type { AstroIntegration } from 'astro'
import type { StarlightPlugin } from '@astrojs/starlight/types'
import { AstroError } from 'astro/errors'

import { remarkStarlightLinksValidator } from './libs/remark'
import { logErrors, validateLinks } from './libs/validation'

export default function starlightLinksValidatorIntegration(): AstroIntegration {
export default function starlightLinksValidatorPlugin(): StarlightPlugin {
return {
name: 'starlight-links-validator',
name: 'starlight-links-validator-plugin',
hooks: {
'astro:config:setup': ({ command, updateConfig }) => {
if (command !== 'build') {
return
}
setup({ addIntegration }) {
addIntegration({
name: 'starlight-links-validator-integration',
hooks: {
'astro:config:setup': ({ command, updateConfig }) => {
if (command !== 'build') {
return
}

updateConfig({
markdown: {
remarkPlugins: [remarkStarlightLinksValidator],
},
})
},
'astro:build:done': ({ dir, pages }) => {
const errors = validateLinks(pages, dir)
updateConfig({
markdown: {
remarkPlugins: [remarkStarlightLinksValidator],
},
})
},
'astro:build:done': ({ dir, pages }) => {
const errors = validateLinks(pages, dir)

logErrors(errors)
logErrors(errors)

if (errors.size > 0) {
throw new AstroError(
'Links validation failed.',
`See the error report above for more informations.\n\nIf you believe this is a bug, please file an issue at https://github.com/HiDeoo/starlight-links-validator/issues/new/choose.`,
)
}
if (errors.size > 0) {
throw new AstroError(
'Links validation failed.',
`See the error report above for more informations.\n\nIf you believe this is a bug, please file an issue at https://github.com/HiDeoo/starlight-links-validator/issues/new/choose.`,
)
}
},
},
})
},
},
}
Expand Down
8 changes: 4 additions & 4 deletions packages/starlight-links-validator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "starlight-links-validator",
"version": "0.4.2",
"license": "MIT",
"description": "Astro integration for Starlight to validate internal links.",
"description": "Starlight plugin to validate internal links.",
"author": "HiDeoo <[email protected]> (https://hideoo.dev)",
"type": "module",
"exports": {
Expand All @@ -11,7 +11,7 @@
},
"scripts": {
"test": "vitest",
"lint": "prettier -c --cache . && eslint . --cache --max-warnings=0 && tsc --noEmit"
"lint": "prettier -c --cache . && eslint . --cache --max-warnings=0"
},
"dependencies": {
"github-slugger": "2.0.0",
Expand Down Expand Up @@ -46,10 +46,10 @@
"sideEffects": false,
"keywords": [
"starlight",
"plugin",
"links",
"validation",
"astro",
"astro-integration"
"astro"
],
"homepage": "https://github.com/HiDeoo/starlight-links-validator",
"repository": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import starlightLinksValidator from '../..'

export default defineConfig({
integrations: [
starlightLinksValidator(),
starlight({
plugins: [starlightLinksValidator()],
sidebar: [],
title: 'Starlight Links Validator Tests',
}),
Expand Down

0 comments on commit 1d8ff99

Please sign in to comment.