Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Virtual" pages prototype #1175

Merged
merged 43 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
fdb96f3
feat: add basic virtual page prototype
HiDeoo Nov 30, 2023
1525ed3
Merge branch 'main' into hd-virtual-pages
HiDeoo Dec 27, 2023
62e3ffc
feat: add virtual frontmatter
HiDeoo Dec 27, 2023
9151563
feat: make `hasSidebar` prop optional
HiDeoo Dec 27, 2023
e49999f
feat: make `headings` prop optional
HiDeoo Dec 27, 2023
4577df5
feat: make `dir` & `lang` props optional
HiDeoo Dec 27, 2023
478ddc2
chore: add example with mininal set of virtual route props
HiDeoo Dec 27, 2023
6aa37e0
fix: virtual page hero
HiDeoo Dec 27, 2023
c45c45f
chore: add banner example
HiDeoo Dec 27, 2023
88455a7
feat: add `makeVirtualStaticPaths()` helper
HiDeoo Dec 29, 2023
5737021
docs: add `isFallback` documentation
HiDeoo Dec 29, 2023
fc20da3
docs: reorder virtual page props
HiDeoo Dec 29, 2023
162b23e
docs: rewrite virtual page code example
HiDeoo Dec 29, 2023
823b259
Merge branch 'main' into hd-virtual-pages
HiDeoo Jan 15, 2024
104ddd0
chore: update pr
HiDeoo Jan 15, 2024
7448aca
Merge branch 'main' into hd-virtual-pages
HiDeoo Jan 23, 2024
7a9db5a
feat: remove `makeVirtualStaticPaths()` helper
HiDeoo Jan 23, 2024
611976a
refactor: isolate virtual page code
HiDeoo Jan 23, 2024
482fb11
feat: add support for edit URLs
HiDeoo Jan 23, 2024
ef9df1f
refactor: move virtual page frontmatter props to a dedicated property
HiDeoo Jan 23, 2024
de6ef91
docs: fix invalid link
HiDeoo Jan 23, 2024
2f6905e
feat: WIP use user frontmatter schema for validation
HiDeoo Jan 30, 2024
ef16232
feat: more WIP to use the user frontmatter schema for validation
HiDeoo Jan 31, 2024
93eb508
feat: use user frontmatter schema for validation
HiDeoo Feb 1, 2024
a887c62
refactor: virtual page type helpers
HiDeoo Feb 1, 2024
2107f4a
Merge branch 'main' into hd-virtual-pages
HiDeoo Feb 10, 2024
b974a7d
chore: fix lockfile
HiDeoo Feb 10, 2024
36ddbe5
chore: bump development and starter templates astro version to `4.3.5`
HiDeoo Feb 10, 2024
3ff92d7
chore: rename virtual pages to Starlight pages
HiDeoo Feb 10, 2024
8678fda
feat: improve Starlight page frontmatter validation errors
HiDeoo Feb 10, 2024
e29eccd
chore: remove `virtual-pages-demo`
HiDeoo Feb 10, 2024
9a04f7d
Chris docs: first pass
delucis Feb 12, 2024
2d7973d
test: remove unused import
HiDeoo Feb 13, 2024
9665a9d
feat: infer slug from `Astro.url`
HiDeoo Feb 13, 2024
a7d66fc
test: add `urlToSlug` root url tests
HiDeoo Feb 14, 2024
8e0c9fa
Add docs link
delucis Feb 16, 2024
4bd9ee3
Fallback improvement
delucis Feb 16, 2024
0741800
Nice whether today
delucis Feb 16, 2024
3a6850c
Merge branch 'main' into pr/1175
delucis Feb 16, 2024
02ca942
Improve custom pages section based on feedback
delucis Feb 16, 2024
802acb0
Add link
delucis Feb 16, 2024
ba4c60d
Comment out `sidebar` docs for first release
delucis Feb 16, 2024
8871b4d
Merge branch 'main' into hd-virtual-pages
delucis Feb 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { defineConfig } from 'astro/config';
import starlight from '@astrojs/starlight';
import { virtualPagesDemo } from 'virtual-pages-demo';

export const locales = {
root: { label: 'English', lang: 'en' },
Expand Down Expand Up @@ -30,6 +31,8 @@ export default defineConfig({
trailingSlash: 'always',
integrations: [
starlight({
// TODO(HiDeoo) Remove me
plugins: [virtualPagesDemo()],
title: 'Starlight',
logo: {
light: '/src/assets/logo-light.svg',
Expand Down
3 changes: 2 additions & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"@types/culori": "^2.0.0",
"astro": "^3.2.3",
"culori": "^3.2.0",
"sharp": "^0.32.5"
"sharp": "^0.32.5",
"virtual-pages-demo": "workspace:*"
},
"devDependencies": {
"hast-util-from-html": "^1.0.2",
Expand Down
149 changes: 149 additions & 0 deletions docs/src/content/docs/reference/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,152 @@ The example above will log a message that includes the provided info message:
```shell
[long-process-plugin] Starting long process…
```

## Route injection

Plugins [adding](#addintegration) an Astro integration can inject routes using the Integrations API [`injectRoute`](https://docs.astro.build/en/reference/integrations-reference/#injectroute-option) function to render dynamically generated content.
By default, pages rendered on custom routes do not use the Starlight layout. To use the Starlight layout, pages must wrap their content with the `<VirtualPage />` component.

```astro
---
// plugin/src/Example.astro
import VirtualPage, {
type VirtualPageProps,
} from '@astrojs/starlight/components/VirtualPage.astro';
import CustomComponent from './CustomComponent.astro';

const props = {
title: 'My custom page',
slug: 'custom-page/example',
template: 'doc',
hasSidebar: true,
headings: [{ depth: 2, slug: 'description', text: 'Description' }],
dir: 'ltr',
lang: 'en',
pagefind: true,
head: [],
} satisfies VirtualPageProps;
---

<VirtualPage {...props}>
<h2 id="description">Description</h2>
<CustomComponent />
</VirtualPage>
```

### Props

#### Required props

The `<VirtualPage />` component requires the following props:

##### `title`

**type:** `string`

The page title displayed at the top of the page, in browser tabs, and in page metadata.

##### `slug`

**Type:** `string`

The slug of the page.

##### `headings`

Type: `{ depth: number; slug: string; text: string }[]`

Array of all headings of the page.

##### `template`

**type:** `'doc' | 'splash'`

Set the layout template for this page.
Use `'splash'` to use a wider layout without any sidebars.

##### `pagefind`

**type:** `boolean`

Set whether this page should be included in the [Pagefind](https://pagefind.app/) search index.

##### `dir`

**Type:** `'ltr' | 'rtl'`

Page writing direction.

##### `lang`

**Type:** `string`

BCP-47 language tag for this page’s locale, e.g. `en`, `zh-CN`, or `pt-BR`.

##### `head`

**Type:** `{ tag: string; attrs: Record<string, string | boolean | undefined>; content: string }[]`

Additional tags to your page’s `<head>`. Similar to the [global `head` option](/reference/configuration/#head).

##### `hasSidebar`

**Type:** `boolean`

Whether or not the sidebar should be displayed on this page.

#### Optional props

Additionaly, the following props can be provided to customize the page:

##### `description`

**type:** `string`

The page description is used for page metadata and will be picked up by search engines and in social media previews.

##### `sidebar`

**type:** `SidebarEntry[] | undefined`
**default:** the sidebar generated based on the [global `sidebar` config](/reference/configuration/#sidebar)

Site navigation sidebar entries for this page or fallback to the global `sidebar` option if not provided.

##### `tableOfContents`

**type:** `false | { minHeadingLevel: number; maxHeadingLevel: number; }`

Overrides the [global `tableOfContents` config](/reference/configuration/#tableofcontents).
Customize the heading levels to be included or set to `false` to hide the table of contents on this page.

##### `lastUpdated`

**type:** `Date`

A valid [YAML timestamp](https://yaml.org/type/timestamp.html) to display the last updated date of the page.

##### `prev`

**type:** `boolean | string | { link?: string; label?: string }`

Overrides the [global `pagination` option](/reference/configuration/#pagination). If a string is specified, the generated link text will be replaced and if an object is specified, both the link and the text will be overridden.

##### `next`

**type:** `boolean | string | { link?: string; label?: string }`

Same as [`prev`](#prev) but for the next page link.

##### `hero`

**type:** [`HeroConfig`](/reference/frontmatter/#heroconfig)

Add a hero component to the top of this page. Works well with `template: splash`. Similar to the [frontmatter `hero` option](/reference/frontmatter/#hero).

##### `banner`

**type:** `{ content: string }`

Displays an announcement banner at the top of this page.

The `content` value can include HTML for links or other content.
Loading