-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add a new option to not error on fallback page links
- Loading branch information
Showing
51 changed files
with
641 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
--- | ||
title: Configuration | ||
--- | ||
|
||
The Starlight Links Validator 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 starlightLinksValidator from 'starlight-links-validator' | ||
|
||
export default defineConfig({ | ||
integrations: [ | ||
starlight({ | ||
plugins: [ | ||
starlightLinksValidator({ | ||
// Configuration options go here. | ||
}), | ||
], | ||
title: 'My Docs', | ||
}), | ||
], | ||
}) | ||
``` | ||
|
||
## Configuration options | ||
|
||
You can pass the following options to the Starlight Links Validator plugin. | ||
|
||
### `errorOnFallbackPages` | ||
|
||
**Type:** `boolean` | ||
**Default:** `true` | ||
|
||
Starlight provides [fallback content](https://starlight.astro.build/guides/i18n/#fallback-content) in the default language for all pages that are not available in the current language. | ||
|
||
By default, the Starlight Links Validator plugin will error if a link points to a fallback page. | ||
If you do not expect to have all pages translated in all configured locales and want to use the fallback pages feature built-in into Starlight, you should set this option to `false`. | ||
|
||
```js {6} | ||
export default defineConfig({ | ||
integrations: [ | ||
starlight({ | ||
plugins: [ | ||
starlightLinksValidator({ | ||
errorOnFallbackPages: false, | ||
}), | ||
], | ||
}), | ||
], | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
.astro | ||
.github/blocks | ||
.next | ||
.tests | ||
.vercel | ||
.vscode-test | ||
.vscode-test-web | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import type { Headings } from './remark' | ||
import type { StarlightUserConfig } from './validation' | ||
|
||
export function getLocaleConfig(config: StarlightUserConfig): LocaleConfig { | ||
if (!config.locales || Object.keys(config.locales).length === 0) return | ||
|
||
let defaultLocale = config.defaultLocale | ||
const locales: string[] = [] | ||
|
||
for (const [dir, locale] of Object.entries(config.locales)) { | ||
if (!locale) continue | ||
|
||
if (dir === 'root') { | ||
if (!locale.lang) continue | ||
|
||
defaultLocale = '' | ||
} | ||
|
||
locales.push(dir) | ||
} | ||
|
||
if (defaultLocale === undefined) return | ||
|
||
return { | ||
defaultLocale, | ||
locales, | ||
} | ||
} | ||
|
||
export function getFallbackHeadings( | ||
path: string, | ||
headings: Headings, | ||
localeConfig: LocaleConfig, | ||
): string[] | undefined { | ||
if (!localeConfig) return | ||
|
||
for (const locale of localeConfig.locales) { | ||
if (path.startsWith(`${locale}/`)) { | ||
const fallbackPath = path.replace( | ||
new RegExp(`^${locale}/`), | ||
localeConfig.defaultLocale === '' ? localeConfig.defaultLocale : `${localeConfig.defaultLocale}/`, | ||
) | ||
|
||
return headings.get(fallbackPath === '' ? '/' : fallbackPath) | ||
} | ||
} | ||
|
||
return | ||
} | ||
|
||
export type LocaleConfig = | ||
| { | ||
defaultLocale: string | ||
locales: string[] | ||
} | ||
| undefined |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.