From 166e22bdf35b9751dc42f5cc6cb27a99b077df93 Mon Sep 17 00:00:00 2001 From: "Fred K. Schott" Date: Thu, 15 Jul 2021 14:13:35 -0400 Subject: [PATCH] merge in docs site (#705) --- docs/.prettierignore | 2 + docs/.prettierrc | 7 + docs/README.md | 17 + docs/astro.config.mjs | 6 + docs/guides/data-fetching.md | 29 - docs/package.json | 22 + docs/public/code.css | 155 + docs/public/favicon.svg | 11 + docs/public/index.css | 378 ++ docs/public/theme.css | 83 + docs/public/theme.js | 12 + docs/snowpack.config.mjs | 7 + docs/src/components/ArticleFooter.astro | 16 + docs/src/components/AstroLogo.astro | 20 + docs/src/components/AvatarList.astro | 151 + docs/src/components/DocSidebar.tsx | 65 + docs/src/components/EditOnGithub.tsx | 25 + docs/src/components/MenuToggle.tsx | 44 + docs/src/components/Note.astro | 48 + docs/src/components/SiteSidebar.astro | 69 + docs/src/components/ThemeToggle.tsx | 97 + docs/src/config.ts | 67 + docs/src/layouts/Main.astro | 248 + docs/src/pages/blog/island-architecture.md | 240 + .../pages}/core-concepts/astro-components.md | 15 +- .../pages}/core-concepts/astro-pages.md | 8 +- .../pages}/core-concepts/collections.md | 1 + .../core-concepts/component-hydration.md | 14 +- docs/{ => src/pages}/core-concepts/layouts.md | 13 +- .../pages}/core-concepts/project-structure.md | 9 +- docs/{ => src/pages}/examples.md | 2 +- docs/src/pages/guides/data-fetching.md | 64 + docs/{ => src/pages}/guides/deploy.md | 15 +- docs/{ => src/pages}/guides/imports.md | 8 +- .../pages}/guides/markdown-content.md | 8 +- docs/{ => src/pages}/guides/publish-to-npm.md | 8 +- docs/{ => src/pages}/guides/styling.md | 2 +- docs/src/pages/index.astro | 251 + docs/{ => src/pages}/installation.md | 0 .../pages}/integrations/data-sources-cms.md | 2 +- .../pages}/integrations/deploy-astro.md | 2 +- .../pages}/integrations/developer-tools.md | 2 +- .../pages}/integrations/state-management.md | 2 +- .../integrations/styles-and-css-libraries.md | 2 +- docs/{ => src/pages}/quick-start.md | 2 +- .../pages}/reference/api-reference.md | 2 +- .../pages}/reference/builtin-components.md | 2 +- .../pages}/reference/cli-reference.md | 2 +- .../reference/configuration-reference.md | 2 +- .../pages}/reference/renderer-reference.md | 0 docs/yarn.lock | 4773 +++++++++++++++++ 51 files changed, 6939 insertions(+), 91 deletions(-) create mode 100644 docs/.prettierignore create mode 100644 docs/.prettierrc create mode 100644 docs/README.md create mode 100644 docs/astro.config.mjs delete mode 100644 docs/guides/data-fetching.md create mode 100644 docs/package.json create mode 100644 docs/public/code.css create mode 100644 docs/public/favicon.svg create mode 100644 docs/public/index.css create mode 100644 docs/public/theme.css create mode 100644 docs/public/theme.js create mode 100644 docs/snowpack.config.mjs create mode 100644 docs/src/components/ArticleFooter.astro create mode 100644 docs/src/components/AstroLogo.astro create mode 100644 docs/src/components/AvatarList.astro create mode 100644 docs/src/components/DocSidebar.tsx create mode 100644 docs/src/components/EditOnGithub.tsx create mode 100644 docs/src/components/MenuToggle.tsx create mode 100644 docs/src/components/Note.astro create mode 100644 docs/src/components/SiteSidebar.astro create mode 100644 docs/src/components/ThemeToggle.tsx create mode 100644 docs/src/config.ts create mode 100644 docs/src/layouts/Main.astro create mode 100644 docs/src/pages/blog/island-architecture.md rename docs/{ => src/pages}/core-concepts/astro-components.md (96%) rename docs/{ => src/pages}/core-concepts/astro-pages.md (94%) rename docs/{ => src/pages}/core-concepts/collections.md (99%) rename docs/{ => src/pages}/core-concepts/component-hydration.md (96%) rename docs/{ => src/pages}/core-concepts/layouts.md (97%) rename docs/{ => src/pages}/core-concepts/project-structure.md (96%) rename docs/{ => src/pages}/examples.md (92%) create mode 100644 docs/src/pages/guides/data-fetching.md rename docs/{ => src/pages}/guides/deploy.md (96%) rename docs/{ => src/pages}/guides/imports.md (98%) rename docs/{ => src/pages}/guides/markdown-content.md (88%) rename docs/{ => src/pages}/guides/publish-to-npm.md (97%) rename docs/{ => src/pages}/guides/styling.md (99%) create mode 100644 docs/src/pages/index.astro rename docs/{ => src/pages}/installation.md (100%) rename docs/{ => src/pages}/integrations/data-sources-cms.md (93%) rename docs/{ => src/pages}/integrations/deploy-astro.md (92%) rename docs/{ => src/pages}/integrations/developer-tools.md (93%) rename docs/{ => src/pages}/integrations/state-management.md (93%) rename docs/{ => src/pages}/integrations/styles-and-css-libraries.md (94%) rename docs/{ => src/pages}/quick-start.md (95%) rename docs/{ => src/pages}/reference/api-reference.md (100%) rename docs/{ => src/pages}/reference/builtin-components.md (100%) rename docs/{ => src/pages}/reference/cli-reference.md (93%) rename docs/{ => src/pages}/reference/configuration-reference.md (97%) rename docs/{ => src/pages}/reference/renderer-reference.md (100%) create mode 100644 docs/yarn.lock diff --git a/docs/.prettierignore b/docs/.prettierignore new file mode 100644 index 000000000..76add878f --- /dev/null +++ b/docs/.prettierignore @@ -0,0 +1,2 @@ +node_modules +dist \ No newline at end of file diff --git a/docs/.prettierrc b/docs/.prettierrc new file mode 100644 index 000000000..945f3a139 --- /dev/null +++ b/docs/.prettierrc @@ -0,0 +1,7 @@ +{ + "singleQuote": true, + "tabWidth": 2, + "endOfLine": "auto", + "trailingComma": "es5", + "printWidth": 80 +} \ No newline at end of file diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 000000000..5fd357fad --- /dev/null +++ b/docs/README.md @@ -0,0 +1,17 @@ +# Astro Docs Astro logo + +## Contributing + +### Pull Requests + +Every pull request needs to be reviewed by another contributor to the documentation to help with the overall quality of the documentation. + +## Running this project + +- Clone/Fork the project +- This project uses yarn to manage dependencies. [Make sure that you have yarn v1 installed.](https://classic.yarnpkg.com/) +- Run `yarn install` to install latest dependencies. +- Run `yarn start` to start the dev server. +- Run `yarn build` to build the final site for production. + +The environment variable `SNOWPACK_PUBLIC_GITHUB_TOKEN` must be set to a personal access token with `public_repo` permissions to prevent rate-limiting. diff --git a/docs/astro.config.mjs b/docs/astro.config.mjs new file mode 100644 index 000000000..fb55c8f6f --- /dev/null +++ b/docs/astro.config.mjs @@ -0,0 +1,6 @@ +export default { + buildOptions: { + site: 'https://astro-docs-preview.vercel.app/', + }, + renderers: ['@astrojs/renderer-preact'], +}; diff --git a/docs/guides/data-fetching.md b/docs/guides/data-fetching.md deleted file mode 100644 index a4d02fd29..000000000 --- a/docs/guides/data-fetching.md +++ /dev/null @@ -1,29 +0,0 @@ ---- -layout: ~/layouts/Main.astro -title: Data Fetching ---- - -Astro components and pages can fetch remote data to help generate your pages. Astro provides two different tools to pages to help you do this: **fetch()** and **top-level await.** - -### `fetch()` - -Astro pages have access to the global `fetch()` function in their setup script. `fetch()` is a native JavaScript API ([MDN](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch)) that lets you make HTTP requests for things like APIs and resources. - -Even though Astro component scripts run inside of Node.js (and not in the browser) Astro provides this native API so that you can fetch data at page build time. - -```astro ---- -const response = await fetch('http://example.com/movies.json'); -const data = await response.json(); -// Remember: Astro component scripts log to the CLI -console.log(data); ---- - -
{JSON.stringify(data)}
-``` - -### Top-level await - -`await` is another native JavaScript feature that lets you await the response of some asynchronous promise ([MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await)). Astro supports `await` in the top-level of your component script. - -**Important:** These are not yet available inside of non-page Astro components. Instead, do all of your data loading inside of your pages, and then pass them to your components as props. diff --git a/docs/package.json b/docs/package.json new file mode 100644 index 000000000..7eb04d1ed --- /dev/null +++ b/docs/package.json @@ -0,0 +1,22 @@ +{ + "name": "@astrojs/docs-template", + "version": "0.0.2", + "private": true, + "scripts": { + "start": "astro dev", + "build": "astro build", + "lint": "run-p --aggregate-output lint:linkcheck", + "lint:linkcheck": "start-test 'yarn start --silent' 3000 'yarn lint:linkcheck:local'", + "lint:linkcheck:local": "blc -ro --user-agent 'broken-link-checker/0.7.8' 'http://localhost:3000'", + "lint:linkcheck:remote": "blc -ro --user-agent 'broken-link-checker/0.7.8' 'https://astro-docs-preview.vercel.app/'", + "format": "prettier -w \"**/*.{css,js,jsx,ts,tsx,md,json}\"" + }, + "devDependencies": { + "@snowpack/plugin-dotenv": "^2.1.0", + "astro": "^0.17.2", + "broken-link-checker": "^0.7.8", + "npm-run-all": "^4.1.5", + "prettier": "^2.3.2", + "start-server-and-test": "^1.12.6" + } +} diff --git a/docs/public/code.css b/docs/public/code.css new file mode 100644 index 000000000..76b44bd24 --- /dev/null +++ b/docs/public/code.css @@ -0,0 +1,155 @@ +.language-css > code, +.language-sass > code, +.language-scss > code { + color: #fd9170; +} + +[class*="language-"] .namespace { + opacity: 0.7; +} + +.token.atrule { + color: #c792ea; +} + +.token.attr-name { + color: #ffcb6b; +} + +.token.attr-value { + color: #a5e844; +} + +.token.attribute { + color: #a5e844; +} + +.token.boolean { + color: #c792ea; +} + +.token.builtin { + color: #ffcb6b; +} + +.token.cdata { + color: #80cbc4; +} + +.token.char { + color: #80cbc4; +} + +.token.class { + color: #ffcb6b; +} + +.token.class-name { + color: #f2ff00; +} + +.token.comment { + color: #999; +} + +.token.constant { + color: #c792ea; +} + +.token.deleted { + color: #ff6666; +} + +.token.doctype { + color: #999; +} + +.token.entity { + color: #ff6666; +} + +.token.function { + color: #c792ea; +} + +.token.hexcode { + color: #f2ff00; +} + +.token.id { + color: #c792ea; + font-weight: bold; +} + +.token.important { + color: #c792ea; + font-weight: bold; +} + +.token.inserted { + color: #80cbc4; +} + +.token.keyword { + color: #c792ea; +} + +.token.number { + color: #fd9170; +} + +.token.operator { + color: #89ddff; +} + +.token.prolog { + color: #999; +} + +.token.property { + color: #80cbc4; +} + +.token.pseudo-class { + color: #a5e844; +} + +.token.pseudo-element { + color: #a5e844; +} + +.token.punctuation { + color: #89ddff; +} + +.token.regex { + color: #f2ff00; +} + +.token.selector { + color: #ff6666; +} + +.token.string { + color: #a5e844; +} + +.token.symbol { + color: #c792ea; +} + +.token.tag { + color: #ff6666; +} + +.token.unit { + color: #fd9170; +} + +.token.url { + color: #ff6666; +} + +.token.variable { + color: #ff6666; +} diff --git a/docs/public/favicon.svg b/docs/public/favicon.svg new file mode 100644 index 000000000..542f90aec --- /dev/null +++ b/docs/public/favicon.svg @@ -0,0 +1,11 @@ + + + + + diff --git a/docs/public/index.css b/docs/public/index.css new file mode 100644 index 000000000..47d4ae681 --- /dev/null +++ b/docs/public/index.css @@ -0,0 +1,378 @@ +* { + box-sizing: border-box; + margin: 0; +} + +:root { + --user-font-scale: 1rem - 16px; + --max-width: calc(100% - 2rem); +} + +@media (min-width: 50em) { + :root { + --max-width: 46em; + } +} + +body { + display: flex; + flex-direction: column; + min-height: 100vh; + font-family: var(--font-body); + font-size: 1rem; + font-size: clamp( + 0.875rem, + 0.4626rem + 1.0309vw + var(--user-font-scale), + 1.125rem + ); + line-height: 1.625; +} + +nav ul { + list-style: none; + padding: 0; +} + +.content main > * + * { + margin-top: 1rem; +} + +/* Typography */ +:is(h1, h2, h3, h4, h5, h6) { + margin-bottom: 1.38rem; + font-weight: 400; + line-height: 1.3; +} + +:is(h1, h2) { + max-width: 40ch; +} + +:is(h2, h3):not(:first-child) { + margin-top: 3rem; +} + +h1 { + font-size: 3.5rem; + font-weight: bold; +} + +h2 { + font-size: 32px; + font-weight: bold; +} + +h3 { + font-size: 24px; + font-weight: bold; +} + +h4 { + font-size: 1rem; + font-weight: bold; +} + +h5 { + font-size: clamp(1.2rem, 1.15rem + 0.125vw, 1.25rem); +} + +p, +.content ul { + color: var(--theme-text-light); +} + +small, +.text_small { + font-size: 0.833rem; +} + +a { + color: var(--theme-text-accent); + font-weight: 400; + text-underline-offset: 0.08em; + display: inline-flex; + align-items: center; + gap: 0.5rem; +} + +a > code:not([class*='language']) { + position: relative; + color: var(--theme-text-accent); + background: transparent; + text-underline-offset: var(--padding-block); +} + +a > code:not([class*='language'])::before { + content: ''; + position: absolute; + top: 0; + right: 0; + bottom: 0; + left: 0; + display: block; + background: var(--theme-accent); + opacity: var(--theme-accent-opacity); + border-radius: var(--border-radius); +} + +a:hover, +a:focus { + text-decoration: underline; +} + +a:focus { + outline: 2px solid currentColor; + outline-offset: 0.25em; +} + +strong { + font-weight: 600; + color: inherit; +} + +/* Supporting Content */ + +code:not([class*='language']) { + --border-radius: 3px; + --padding-block: 0.2rem; + --padding-inline: 0.33rem; + + font-family: var(--font-mono); + font-size: 0.85em; + color: var(--theme-code-inline-text); + background-color: var(--theme-code-inline-bg); + padding: var(--padding-block) var(--padding-inline); + margin: calc(var(--padding-block) * -1) -0.125em; + border-radius: var(--border-radius); +} + +pre > code:not([class*='language']) { + background-color: transparent; + padding: 0; + margin: 0; + border-radius: 0; + color: inherit; +} + +pre { + position: relative; + background-color: var(--theme-code-bg); + color: var(--theme-code-text); + --padding-block: 1rem; + --padding-inline: 2rem; + padding: var(--padding-block) var(--padding-inline); + padding-right: calc(var(--padding-inline) * 2); + + line-height: 1.414; + overflow-y: hidden; + overflow-x: auto; +} + +@media (min-width: 37.75em) { + pre { + --padding-inline: 1.25rem; + border-radius: 8px; + } +} + +blockquote { + margin: 2rem 0; + padding: 1.25em 1.5rem; + border-left: 3px solid var(--theme-text-light); + background-color: var(--theme-bg-offset); + border-radius: 0 0.25rem 0.25rem 0; + line-height: 1.7; +} + +img { + max-width: 100%; +} + +.flex { + display: flex; + align-items: center; +} + +header button { + background-color: var(--theme-bg); +} + +header button:hover, +header button:focus { + outline: var(--theme-text) solid 1px; +} + +header button:active, +header button[aria-pressed='true'] { + background: var(--theme-text); + color: var(--theme-bg); +} + +button { + display: flex; + align-items: center; + justify-items: center; + gap: 0.25em; + padding: 0.33em 0.67em; + border: 0; + background: var(--theme-bg); + display: flex; + font-size: 1rem; + align-items: center; + gap: 0.25em; + border-radius: 99em; + color: var(--theme-text); + background-color: var(--theme-bg); +} + +#theme-toggle { + display: flex; + align-items: center; + gap: 0.25em; + padding: 0.33em 0.67em; + border-radius: 99em; + background-color: var(--theme-bg); +} + +#theme-toggle > label:focus-within { + outline: 2px solid transparent; + box-shadow: 0 0 0 0.08em var(--theme-accent), 0 0 0 0.12em white; +} + +#theme-toggle > label { + position: relative; + display: flex; + align-items: center; + justify-content: center; + font-size: 1.5rem; + width: 1.5rem; + height: 1.5rem; + opacity: 0.5; + transition: transform 120ms ease-out, opacity 120ms ease-out; +} + +#theme-toggle > label:hover, +#theme-toggle > label:focus { + transform: scale(1.125); + opacity: 1; +} + +#theme-toggle .checked { + color: var(--theme-accent); + transform: scale(1.125); + opacity: 1; +} + +input[name='theme-toggle'] { + position: absolute; + opacity: 0; + top: 0; + right: 0; + bottom: 0; + left: 0; + z-index: -1; +} + +.sidebar-nav { + width: 100%; + position: sticky; + min-height: calc(100vh - 3.5rem); + height: calc(100vh - 3.5rem); + top: 3.5rem; +} +.sidebar-nav-inner { + height: 100%; + padding: 2rem 0; + overflow: auto; +} + +h2.heading { + font-size: 1rem; + font-weight: 700; + padding: 0.1rem 1rem; + text-transform: uppercase; + margin-bottom: 0.5rem; +} + +.header-link { + font-size: 1rem; + padding: 0.1rem 0 0.1rem 1rem; + border-left: 4px solid var(--theme-divider); +} + +.header-link:hover, +.header-link:focus { + border-left-color: var(--color-gray-300); +} +.header-link:focus-within { + color: var(--theme-text-light); + border-left-color: var(--color-gray-600); +} + +.header-link.depth-3 { + padding-left: 2rem; +} +.header-link.depth-4 { + padding-left: 3rem; +} + +.header-link a { + font: inherit; + color: inherit; + text-decoration: none; +} + +.edit-on-github { + text-decoration: none; + font: inherit; + color: inherit; + font-size: 1rem; +} + +/* Scrollbar */ + +/* width */ +::-webkit-scrollbar { + width: 0.5rem; +} + +/* Track */ +::-webkit-scrollbar-track { + background: var(--theme-divider); + border-radius: 1rem; +} + +/* Handle */ +::-webkit-scrollbar-thumb { + background: var(--theme-text-lighter); + border-radius: 1rem; +} + +/* Handle on hover */ +::-webkit-scrollbar-thumb:hover { + background: var(--theme-text-light); +} + +/* Buttons */ +::-webkit-scrollbar-button { + display: none; +} +/* Scrollbar - End */ + +/* Screenreader Only Text */ +.sr-only { + position: absolute; + width: 1px; + height: 1px; + padding: 0; + margin: -1px; + overflow: hidden; + clip: rect(0, 0, 0, 0); + white-space: nowrap; + border-width: 0; +} +/* Screenreader Only Text - End */ + +:target { + scroll-margin-top: 4rem; +} diff --git a/docs/public/theme.css b/docs/public/theme.css new file mode 100644 index 000000000..22d765714 --- /dev/null +++ b/docs/public/theme.css @@ -0,0 +1,83 @@ +:root { + --font-fallback: -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial, + sans-serif, Apple Color Emoji, Segoe UI Emoji; + --font-body: system-ui, var(--font-fallback); + --font-mono: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', + monospace; + + --color-white: #fff; + --color-black: #000014; + + --color-gray-50: #f9fafb; + --color-gray-100: #f3f4f6; + --color-gray-200: #e5e7eb; + --color-gray-300: #d1d5db; + --color-gray-400: #9ca3af; + --color-gray-500: #6b7280; + --color-gray-600: #4b5563; + --color-gray-700: #374151; + --color-gray-800: #1f2937; + --color-gray-900: #111827; + --color-gray-950: #090e18; + + --color-blue: #3894ff; + --color-blue-dark: #1c5fac; + --color-blue-rgb: 56, 148, 255; + --color-green: #17c083; + --color-green-rgb: 23, 192, 131; + --color-orange: #ff5d01; + --color-orange-rgb: 255, 93, 1; + --color-purple: #882de7; + --color-purple-rgb: 136, 45, 231; + --color-red: #ff1639; + --color-red-rgb: 255, 22, 57; + --color-yellow: #ffbe2d; + --color-yellow-rgb: 255, 190, 45; +} + +:root { + color-scheme: light; + --theme-accent: var(--color-blue); + --theme-accent-rgb: var(--color-blue-rgb); + --theme-accent-opacity: 0.1; + --theme-divider: var(--color-gray-100); + --theme-text: var(--color-gray-800); + --theme-text-light: var(--color-gray-600); + --theme-text-lighter: var(--color-gray-400); + --theme-text-accent: var(--color-blue); + --theme-bg: var(--color-white); + --theme-bg-hover: var(--color-gray-50); + --theme-bg-offset: var(--color-gray-100); + --theme-bg-accent: rgba(var(--theme-accent-rgb), var(--theme-accent-opacity)); + --theme-code-inline-bg: var(--color-gray-100); + --theme-code-inline-text: var(--theme-text); + --theme-code-bg: var(--color-gray-700); + --theme-code-text: var(--color-gray-100); +} + +body { + background: var(--theme-bg); + color: var(--theme-text); +} + +:root.theme-dark { + color-scheme: dark; + --theme-accent-opacity: 0.3; + --theme-divider: var(--color-gray-900); + --theme-text: var(--color-gray-200); + --theme-text-light: var(--color-gray-300); + --theme-text-lighter: var(--color-gray-600); + --theme-text-accent: var(--color-white); + --theme-bg: var(--color-gray-800); + --theme-bg-hover: var(--color-gray-600); + --theme-bg-offset: var(--color-gray-950); + --theme-code-inline-bg: var(--color-gray-600); + --theme-code-inline-text: var(--color-white); + --theme-code-bg: var(--color-gray-950); + --theme-code-text: var(--color-white); +} + +::selection { + color: var(--theme-text-accent); + background-color: rgba(var(--theme-accent-rgb), var(--theme-accent-opacity)); +} diff --git a/docs/public/theme.js b/docs/public/theme.js new file mode 100644 index 000000000..91abd5504 --- /dev/null +++ b/docs/public/theme.js @@ -0,0 +1,12 @@ +(() => { + const root = document.documentElement; + if ( + localStorage.theme === 'dark' || + (!('theme' in localStorage) && + window.matchMedia('(prefers-color-scheme: dark)').matches) + ) { + root.classList.add('theme-dark'); + } else { + root.classList.remove('theme-dark'); + } +})(); diff --git a/docs/snowpack.config.mjs b/docs/snowpack.config.mjs new file mode 100644 index 000000000..e811f7990 --- /dev/null +++ b/docs/snowpack.config.mjs @@ -0,0 +1,7 @@ +export default { + alias: { + components: './src/components', + '~': './src', + }, + plugins: ['@snowpack/plugin-dotenv'], +}; diff --git a/docs/src/components/ArticleFooter.astro b/docs/src/components/ArticleFooter.astro new file mode 100644 index 000000000..48de51054 --- /dev/null +++ b/docs/src/components/ArticleFooter.astro @@ -0,0 +1,16 @@ +--- +import AvatarList from './AvatarList.astro'; +const { path } = Astro.props; +--- + + + + diff --git a/docs/src/components/AstroLogo.astro b/docs/src/components/AstroLogo.astro new file mode 100644 index 000000000..ff1939ad9 --- /dev/null +++ b/docs/src/components/AstroLogo.astro @@ -0,0 +1,20 @@ +--- +const {size} = Astro.props; +--- + \ No newline at end of file diff --git a/docs/src/components/AvatarList.astro b/docs/src/components/AvatarList.astro new file mode 100644 index 000000000..09fc089b9 --- /dev/null +++ b/docs/src/components/AvatarList.astro @@ -0,0 +1,151 @@ +--- +// fetch all commits for just this page's path +const { path } = Astro.props; +const url = `https://api.github.com/repos/snowpackjs/astro-docs/commits?path=${path}`; +const commitsURL = `https://github.com/snowpackjs/astro-docs/commits/main/${path}`; + +async function getCommits(url) { + try { + const token = import.meta.env.SNOWPACK_PUBLIC_GITHUB_TOKEN; + if (!token) { + throw new Error( + 'Cannot find "SNOWPACK_PUBLIC_GITHUB_TOKEN" used for escaping rate-limiting.' + ); + } + + const auth = `Basic ${Buffer.from(token, "binary").toString("base64")}`; + + const res = await fetch(url, { + method: "GET", + headers: { + Authorization: auth, + "User-Agent": "astro-docs/1.0", + }, + }); + + const data = await res.json(); + + if (!res.ok) { + throw new Error( + `Request to fetch commits failed. Reason: ${res.statusText} + Message: ${data.message}` + ); + } + + return data; + } catch (e) { + console.warn(`[error] /src/components/AvatarList.astro + ${e?.message ?? e}`); + return new Array(); + } +} + +function removeDups(arr) { + if (!arr) { + return new Array(); + } + let map = new Map(); + + for (let item of arr) { + let author = item.author; + // Deduplicate based on author.id + map.set(author.id, { login: author.login, id: author.id }); + } + + return Array.from(map.values()); +} + +const data = await getCommits(url); +const unique = removeDups(data); +const recentContributors = unique.slice(0, 3); // only show avatars for the 3 most recent contributors +const additionalContributors = unique.length - recentContributors.length; // list the rest of them as # of extra contributors + +--- + +
+ + {additionalContributors > 0 && {`and ${additionalContributors} additional contributor${additionalContributors > 1 ? 's' : ''}.`}} + {unique.length === 0 && Contributors} +
+ + diff --git a/docs/src/components/DocSidebar.tsx b/docs/src/components/DocSidebar.tsx new file mode 100644 index 000000000..24e9dc4d9 --- /dev/null +++ b/docs/src/components/DocSidebar.tsx @@ -0,0 +1,65 @@ +import type { FunctionalComponent } from 'preact'; +import { h } from 'preact'; +import { useState, useEffect, useRef } from 'preact/hooks'; +import EditOnGithub from './EditOnGithub'; + +const DocSidebar: FunctionalComponent<{ headers: any[]; editHref: string }> = ({ + headers = [], + editHref, +}) => { + const itemOffsets = useRef([]); + const [activeId, setActiveId] = useState(undefined); + + useEffect(() => { + const getItemOffsets = () => { + const titles = document.querySelectorAll('article :is(h1, h2, h3, h4)'); + itemOffsets.current = Array.from(titles).map((title) => ({ + id: title.id, + topOffset: title.getBoundingClientRect().top + window.scrollY, + })); + }; + + getItemOffsets(); + window.addEventListener('resize', getItemOffsets); + + return () => { + window.removeEventListener('resize', getItemOffsets); + }; + }, []); + + return ( + + ); +}; + +export default DocSidebar; diff --git a/docs/src/components/EditOnGithub.tsx b/docs/src/components/EditOnGithub.tsx new file mode 100644 index 000000000..5ff74e364 --- /dev/null +++ b/docs/src/components/EditOnGithub.tsx @@ -0,0 +1,25 @@ +import type { FunctionalComponent } from 'preact'; +import { h } from 'preact'; + +const EditOnGithub: FunctionalComponent<{ href: string }> = ({ href }) => { + return ( + + + + + + + Edit on GitHub + + ); +}; + +export default EditOnGithub; diff --git a/docs/src/components/MenuToggle.tsx b/docs/src/components/MenuToggle.tsx new file mode 100644 index 000000000..605581077 --- /dev/null +++ b/docs/src/components/MenuToggle.tsx @@ -0,0 +1,44 @@ +import type { FunctionalComponent } from 'preact'; +import { h, Fragment } from 'preact'; +import { useState, useEffect } from 'preact/hooks'; + +const MenuToggle: FunctionalComponent = () => { + const [sidebarShown, setSidebarShown] = useState(false); + + useEffect(() => { + const body = document.getElementsByTagName('body')[0]; + if (sidebarShown) { + body.classList.add('mobile-sidebar-toggle'); + } else { + body.classList.remove('mobile-sidebar-toggle'); + } + }, [sidebarShown]); + + return ( + + ); +}; + +export default MenuToggle; diff --git a/docs/src/components/Note.astro b/docs/src/components/Note.astro new file mode 100644 index 000000000..c3ae29cb4 --- /dev/null +++ b/docs/src/components/Note.astro @@ -0,0 +1,48 @@ +--- +const { type = 'tip', title } = Astro.props; +--- + + + + diff --git a/docs/src/components/SiteSidebar.astro b/docs/src/components/SiteSidebar.astro new file mode 100644 index 000000000..6d003d71d --- /dev/null +++ b/docs/src/components/SiteSidebar.astro @@ -0,0 +1,69 @@ +--- +import { sidebar } from '../config.ts'; +const {currentPage} = Astro.props; +--- + + + + + \ No newline at end of file diff --git a/docs/src/components/ThemeToggle.tsx b/docs/src/components/ThemeToggle.tsx new file mode 100644 index 000000000..31ab5ea74 --- /dev/null +++ b/docs/src/components/ThemeToggle.tsx @@ -0,0 +1,97 @@ +import type { FunctionalComponent } from 'preact'; +import { h, Fragment } from 'preact'; +import { useState, useEffect } from 'preact/hooks'; + +const themes = ['system', 'light', 'dark']; + +const icons = [ + + + , + + + , + + + , +]; + +const ThemeToggle: FunctionalComponent = () => { + const [theme, setTheme] = useState(themes[0]); + + useEffect(() => { + const user = localStorage.getItem('theme'); + if (!user) return; + setTheme(user); + }, []); + + useEffect(() => { + const root = document.documentElement; + if (theme === 'system') { + localStorage.removeItem('theme'); + if (window.matchMedia('(prefers-color-scheme: dark)').matches) { + root.classList.add('theme-dark'); + } else { + root.classList.remove('theme-dark'); + } + } else { + localStorage.setItem('theme', theme); + if (theme === 'light') { + root.classList.remove('theme-dark'); + } else { + root.classList.add('theme-dark'); + } + } + }, [theme]); + + return ( +
+ {themes.map((t, i) => { + const icon = icons[i]; + const checked = t === theme; + return ( + + ); + })} +
+ ); +}; + +export default ThemeToggle; diff --git a/docs/src/config.ts b/docs/src/config.ts new file mode 100644 index 000000000..bb96ac4e9 --- /dev/null +++ b/docs/src/config.ts @@ -0,0 +1,67 @@ +export const sidebar = [ + { + text: 'Setup', + link: '', + children: [ + { text: 'Installation', link: 'installation' }, + { text: 'Quickstart', link: 'quick-start' }, + { text: 'Examples', link: 'examples' }, + ], + }, + { + text: 'Basics', + link: 'core-concepts', + children: [ + { text: 'Project Structure', link: 'core-concepts/project-structure' }, + { text: 'Components', link: 'core-concepts/astro-components' }, + { text: 'Pages', link: 'core-concepts/astro-pages' }, + { text: 'Layouts', link: 'core-concepts/layouts' }, + { text: 'Collections', link: 'core-concepts/collections' }, + { text: 'Partial Hydration', link: 'core-concepts/component-hydration' }, + ], + }, + { + text: 'Guides', + link: 'guides', + children: [ + { text: 'Styling & CSS', link: 'guides/styling' }, + { text: 'Data Fetching', link: 'guides/data-fetching' }, + { text: 'Markdown', link: 'guides/markdown-content' }, + { text: 'Supported Imports', link: 'guides/imports' }, + // To be written when https://github.com/snowpackjs/astro/issues/501 is completed + // { text: 'Pagination', link: 'guides/pagination' }, + { text: 'Deploy a Website', link: 'guides/deploy' }, + { text: 'Publish a Component', link: 'guides/publish-to-npm' }, + ], + }, + { + text: 'Reference', + link: 'reference', + children: [ + { text: 'Built-In Components', link: 'reference/builtin-components' }, + { text: 'API Reference', link: 'reference/api-reference' }, + { text: 'CLI Reference', link: 'reference/cli-reference' }, + { + text: 'Configuration Reference', + link: 'reference/configuration-reference', + }, + { text: 'Renderer Reference', link: 'reference/renderer-reference' }, + ], + }, + // To add once rest of the site is complete + // see https://github.com/snowpackjs/astro-docs/issues/9 + // { + // text: 'Integrations', + // link: 'integrations', + // children: [ + // { text: 'Deploy Astro', link: 'integrations/deploy-astro' }, + // { text: 'Data Sources / CMS', link: 'integrations/data-sources-cms' }, + // { text: 'State Management', link: 'integrations/state-management' }, + // { + // text: 'Styles & CSS Libraries', + // link: 'integrations/styles-and-css-libraries', + // }, + // { text: 'Developer Tools', link: 'integrations/developer-tools' }, + // ], + // }, +]; diff --git a/docs/src/layouts/Main.astro b/docs/src/layouts/Main.astro new file mode 100644 index 000000000..3b98d88b6 --- /dev/null +++ b/docs/src/layouts/Main.astro @@ -0,0 +1,248 @@ +--- +import ArticleFooter from '../components/ArticleFooter.astro'; +import SiteSidebar from '../components/SiteSidebar.astro'; +import ThemeToggle from '../components/ThemeToggle.tsx'; +import DocSidebar from '../components/DocSidebar.tsx'; +import MenuToggle from '../components/MenuToggle.tsx'; + +const { content } = Astro.props; +const headers = content?.astro?.headers; +const currentPage = Astro.request.url.pathname; +const currentFile = currentPage === '/' ? 'src/pages/index.md' : `src/pages${currentPage.replace(/\/$/, "")}.md`; +const githubEditUrl = `https://github.com/snowpackjs/astro-docs/blob/main/${currentFile}`; +--- + + + + + + {content.title} + + + + +