Skip to content

Commit

Permalink
docs: build with starlight(astro)
Browse files Browse the repository at this point in the history
  • Loading branch information
sibiraj-s committed Jun 12, 2023
1 parent 8dd53d8 commit 9b9ddfb
Show file tree
Hide file tree
Showing 47 changed files with 2,177 additions and 3,140 deletions.
2 changes: 1 addition & 1 deletion .lintstagedrc.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'*.{js,ts}': eslint --fix
'projects/**/*.html': eslint --fix
'docs/**/*.html': prettier --write
'*.{md,css,astro}': prettier --write
'*.{md,mdx,css,astro}': prettier --write
8 changes: 8 additions & 0 deletions .prettierrc.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
singleQuote: true
printWidth: 120
semi: true

plugins:
- prettier-plugin-astro

overrides:
- files: '*.astro'
options:
parser: 'astro'
161 changes: 37 additions & 124 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,141 +1,54 @@
# Docs Site
# docs site: built with Startlight(Astro)

[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/sibiraj-s/ngx-editor/tree/master/docs)
[![Open with CodeSandbox](https://assets.codesandbox.io/github/button-edit-lime.svg)](https://codesandbox.io/s/github/sibiraj-s/ngx-editor/tree/master/docs)

## Commands Cheatsheet

All commands are run from the root of the project, from a terminal:

| Command | Action |
| :--------------------- | :----------------------------------------------- |
| `npm install` | Installs dependencies |
| `npm run dev` | Starts local dev server at `localhost:3000` |
| `npm run build` | Build your production site to `./dist/` |
| `npm run preview` | Preview your build locally, before deploying |
| `npm run astro ...` | Run CLI commands like `astro add`, `astro check` |
| `npm run astro --help` | Get help using the Astro CLI |

To deploy your site to production, check out our [Deploy an Astro Website](https://docs.astro.build/guides/deploy) guide.

## New to Astro?

Welcome! Check out [documentation](https://docs.astro.build) or jump into our [Discord server](https://astro.build/chat).

## Customize This Theme

### Site metadata

`src/config.ts` contains several data objects that describe metadata about your site like title, description, default language, and Open Graph details. You can customize these to match your project.

### CSS styling

The theme's look and feel is controlled by a few key variables that you can customize yourself. You'll find them in the `src/styles/theme.css` CSS file.

If you've never worked with CSS variables before, give [MDN's guide on CSS variables](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties) a quick read.

This theme uses a "cool blue" accent color by default. To customize this for your project, change the `--theme-accent` variable to whatever color you'd like:

```diff
/* src/styles/theme.css */
:root {
color-scheme: light;
- --theme-accent: hsla(var(--color-blue), 1);
+ --theme-accent: hsla(var(--color-red), 1); /* or: hsla(#FF0000, 1); */
```bash
git clone https://github.com/sibiraj-s/ngx-editor # clone the repo
cd docs # navigate to docs
npm install # install the dependencies
npm run dev # start the dev server
```

## Page metadata

Astro uses frontmatter in Markdown pages to choose layouts and pass properties to those layouts. If you are using the default layout, you can customize the page in many different ways to optimize SEO and other things. For example, you can use the `title` and `description` properties to set the document title, meta title, meta description, and Open Graph description.

```markdown
---
title: Example title
description: Really cool docs example that uses Astro
layout: ../../layouts/MainLayout.astro
---

# Page content...
```
[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/sibiraj-s/ngx-editor/tree/master/docs)
[![Open with CodeSandbox](https://assets.codesandbox.io/github/button-edit-lime.svg)](https://codesandbox.io/s/github/sibiraj-s/ngx-editor/tree/master/docs)

For more SEO related properties, look at `src/components/HeadSEO.astro`
> 🧑‍🚀 **Seasoned astronaut?** Delete this file. Have fun!
### Sidebar navigation
## 🚀 Project Structure

The sidebar navigation is controlled by the `SIDEBAR` variable in your `src/config.ts` file. You can customize the sidebar by modifying this object. A default, starter navigation has already been created for you.
Inside of your Astro + Starlight project, you'll see the following folders and files:

```ts
export const SIDEBAR = {
en: {
'Section Header': [
{ text: 'Introduction', link: 'en/introduction' },
{ text: 'Page 2', link: 'en/page-2' },
{ text: 'Page 3', link: 'en/page-3' },
],
'Another Section': [{ text: 'Page 4', link: 'en/page-4' }],
},
};
```

Note the top-level `en` key: This is needed for multi-language support. You can change it to whatever language you'd like, or add new languages as you go. More details on this below.

### Multiple Languages support

The Astro docs template supports multiple languages out of the box. The default theme only shows `en` documentation, but you can enable multi-language support features by adding a second language to your project.

To add a new language to your project, you'll want to extend the current `src/content/docs/[lang]/...` layout:

```diff
📂 src/content/docs
┣ 📂 en
┃ ┣ 📜 page-1.md
┃ ┣ 📜 page-2.md
┃ ┣ 📜 page-3.astro
+ ┣ 📂 es
+ ┃ ┣ 📜 page-1.md
+ ┃ ┣ 📜 page-2.md
+ ┃ ┣ 📜 page-3.astro
.
├── public/
├── src/
│ ├── assets/
│ ├── content/
│ │ ├── docs/en
│ │ └── config.ts
│ └── env.d.ts
├── astro.config.mjs
├── package.json
└── tsconfig.json
```

You'll also need to add the new language name to the `KNOWN_LANGUAGES` map in your `src/config.ts` file. This will enable your new language switcher in the site header.

```diff
// src/config.ts
export const KNOWN_LANGUAGES = {
English: 'en',
+ Spanish: 'es',
};
```
Starlight looks for `.md` or `.mdx` files in the `src/content/docs/` directory. Each file is exposed as a route based on its file name.

Last step: you'll need to add a new entry to your sidebar, to create the table of contents for that language. While duplicating every page might not sound ideal to everyone, this extra control allows you to create entirely custom content for every language.
Images can be added to `src/assets/` and embedded in Markdown with a relative link.

> Make sure the sidebar `link` value points to the correct language!
Static assets, like favicons, can be placed in the `public/` directory.

```diff
// src/config.ts
export const SIDEBAR = {
en: [
{ text: 'Section Header', header: true, },
{ text: 'Introduction', link: 'en/introduction' },
// ...
],
+ es: [
+ { text: 'Encabezado de sección', header: true, },
+ { text: 'Introducción', link: 'es/introduction' },
+ // ...
+ ],
};
## 🧞 Commands

// ...
```
All commands are run from the root of the project, from a terminal:

If you plan to use Spanish as the default language, you just need to modify the redirect path in `src/pages/index.astro`:
| Command | Action |
| :------------------------ | :----------------------------------------------- |
| `npm install` | Installs dependencies |
| `npm run dev` | Starts local dev server at `localhost:3000` |
| `npm run build` | Build your production site to `./dist/` |
| `npm run preview` | Preview your build locally, before deploying |
| `npm run astro ...` | Run CLI commands like `astro add`, `astro check` |
| `npm run astro -- --help` | Get help using the Astro CLI |

```diff
<script>
- window.location.pathname = `/en/introduction`;
+ window.location.pathname = `/es/introduction`;
</script>
```
## 👀 Want to learn more?

You can also remove the above script and write a landing page in Spanish instead.
Check out [Starlight’s docs](https://starlight.astro.build/), read [the Astro documentation](https://docs.astro.build), or jump into the [Astro Discord server](https://astro.build/chat).
93 changes: 62 additions & 31 deletions docs/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,38 +1,69 @@
import { defineConfig } from 'astro/config';
import preact from '@astrojs/preact';
import react from '@astrojs/react';

const github = () => {
/** @type {import('astro').AstroIntegration}} */
const adapter = {
name: 'github',
hooks: {
'astro:config:setup': ({ command, config, updateConfig }) => {
if (command !== 'build') {
updateConfig({
site: `http://localhost:${config.server.port}`,
});
return;
}

updateConfig({
site: 'https://sibiraj-s.github.io/ngx-editor/',
base: '/ngx-editor',
});
},
},
};

return adapter;
};
import starlight from '@astrojs/starlight';

// https://astro.build/config
export default defineConfig({
integrations: [
// Enable Preact to support Preact JSX components.
preact(),
// Enable React for the Algolia search component.
react(),
starlight({
title: 'NgxEditor',
description: 'The Rich Text Editor for Angular, Built on ProseMirror',
defaultLocale: 'root',
locales: {
en: {
label: 'English',
lang: 'en',
},
},
logo: {
src: '/src/assets/ang_edit_32.png',
},
customCss: process.env.NO_GRADIENTS ? [] : ['/src/assets/landing.css'],
social: {
github: 'https://github.com/sibiraj-s/ngx-editor',
},
editLink: {
baseUrl: 'https://github.com/sibiraj-s/ngx-editor/tree/master/docs/',
},
sidebar: [
{
label: '',
items: [
{ label: 'Introduction', link: 'en/introduction' },
{ label: 'Quick Start', link: 'en/quickstart' },
{ label: 'Editor', link: 'en/editor' },
{ label: 'Configuration', link: 'en/configuration' },
{ label: 'Schema', link: 'en/schema' },
{ label: 'Commands', link: 'en/commands' },
{ label: 'Menu', link: 'en/menu' },
{ label: 'Convert JSON doc to HTML', link: 'en/doc-html-doc' },
],
},
{
label: 'Examples',
items: [
{ label: 'Full Featured Editor', link: 'en/examples/full-featured-editor' },
{ label: 'History', link: 'en/examples/history' },
{ label: 'Input Rules', link: 'en/examples/input-rules' },
{ label: 'Shortcuts', link: 'en/examples/shortcuts' },
{ label: 'Reactive Forms', link: 'en/examples/reactive-forms' },
{ label: 'NgModel Binding', link: 'en/examples/ng-model' },
{ label: 'Collaborative Editing', link: 'en/examples/collab' },
{ label: 'Floating Menu', link: 'en/examples/floating-menu' },
{ label: 'CodeMirror', link: 'en/examples/codemirror' },
{ label: 'Mentions & Tags', link: 'en/examples/mentions' },
],
},
{
label: 'Migrations',
items: [
{ label: 'From v4 or other editors to v5/v6', link: 'en/migrations/migration' },
{ label: 'v5 to v6', link: 'en/migrations/migration-5-6' },
{ label: 'v6 to v7', link: 'en/migrations/migration-6-7' },
{ label: 'v7 to v8', link: 'en/migrations/migration-7-8' },
{ label: 'v8 to v9', link: 'en/migrations/migration-8-9' },
]
}
],
}),
],
adapter: github(),
});
Loading

0 comments on commit 9b9ddfb

Please sign in to comment.