From 7d719ff75d75143f0dfe54dd00bab53e2a27aa2b Mon Sep 17 00:00:00 2001 From: Kitto Khrangtong Date: Fri, 11 Jun 2021 16:33:36 -0400 Subject: [PATCH] Create initial docs site (#389) * create initial docs site * change copy for title and header to say Astro Docs * create initial docs site * remove text merge changes * change workspaceRoot and remove yarn.lock from docs-www * add docs-www to workspace Co-authored-by: Kitto Khrangtong --- docs-www/.gitignore | 18 + docs-www/astro.config.mjs | 5 + docs-www/package.json | 15 + docs-www/public/code.css | 155 +++++++++ docs-www/public/favicon.svg | 11 + docs-www/public/index.css | 350 ++++++++++++++++++++ docs-www/public/theme.css | 73 ++++ docs-www/public/theme.js | 8 + docs-www/src/components/ArticleFooter.astro | 15 + docs-www/src/components/AvatarList.astro | 74 +++++ docs-www/src/components/DocSidebar.tsx | 61 ++++ docs-www/src/components/EditOnGithub.tsx | 26 ++ docs-www/src/components/Note.astro | 49 +++ docs-www/src/components/SiteSidebar.astro | 20 ++ docs-www/src/components/ThemeToggle.tsx | 71 ++++ docs-www/src/config.ts | 12 + docs-www/src/layouts/Main.astro | 228 +++++++++++++ docs-www/src/pages/example.md | 35 ++ docs-www/src/pages/guides.md | 0 docs-www/src/pages/index.astro | 64 ++++ package.json | 5 +- yarn.lock | 3 - 22 files changed, 1293 insertions(+), 5 deletions(-) create mode 100644 docs-www/.gitignore create mode 100644 docs-www/astro.config.mjs create mode 100644 docs-www/package.json create mode 100644 docs-www/public/code.css create mode 100644 docs-www/public/favicon.svg create mode 100644 docs-www/public/index.css create mode 100644 docs-www/public/theme.css create mode 100644 docs-www/public/theme.js create mode 100644 docs-www/src/components/ArticleFooter.astro create mode 100644 docs-www/src/components/AvatarList.astro create mode 100644 docs-www/src/components/DocSidebar.tsx create mode 100644 docs-www/src/components/EditOnGithub.tsx create mode 100644 docs-www/src/components/Note.astro create mode 100644 docs-www/src/components/SiteSidebar.astro create mode 100644 docs-www/src/components/ThemeToggle.tsx create mode 100644 docs-www/src/config.ts create mode 100644 docs-www/src/layouts/Main.astro create mode 100644 docs-www/src/pages/example.md create mode 100644 docs-www/src/pages/guides.md create mode 100644 docs-www/src/pages/index.astro diff --git a/docs-www/.gitignore b/docs-www/.gitignore new file mode 100644 index 000000000..d436c6dad --- /dev/null +++ b/docs-www/.gitignore @@ -0,0 +1,18 @@ +# build output +dist + +# dependencies +node_modules/ +.snowpack/ + +# logs +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# environment variables +.env +.env.production + +# macOS-specific files +.DS_Store diff --git a/docs-www/astro.config.mjs b/docs-www/astro.config.mjs new file mode 100644 index 000000000..d97e2804d --- /dev/null +++ b/docs-www/astro.config.mjs @@ -0,0 +1,5 @@ +export default { + renderers: [ + '@astrojs/renderer-preact' + ] +}; diff --git a/docs-www/package.json b/docs-www/package.json new file mode 100644 index 000000000..5a7ae8749 --- /dev/null +++ b/docs-www/package.json @@ -0,0 +1,15 @@ +{ + "name": "docs-www", + "version": "0.0.1", + "private": true, + "scripts": { + "start": "astro dev", + "build": "astro build" + }, + "devDependencies": { + "astro": "^0.13.0" + }, + "snowpack": { + "workspaceRoot": ".." + } +} \ No newline at end of file diff --git a/docs-www/public/code.css b/docs-www/public/code.css new file mode 100644 index 000000000..54b2c5094 --- /dev/null +++ b/docs-www/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: #616161; +} + +.token.constant { + color: #c792ea; +} + +.token.deleted { + color: #ff6666; +} + +.token.doctype { + color: #616161; +} + +.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: #616161; +} + +.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-www/public/favicon.svg b/docs-www/public/favicon.svg new file mode 100644 index 000000000..542f90aec --- /dev/null +++ b/docs-www/public/favicon.svg @@ -0,0 +1,11 @@ + + + + + diff --git a/docs-www/public/index.css b/docs-www/public/index.css new file mode 100644 index 000000000..c5ae87f5c --- /dev/null +++ b/docs-www/public/index.css @@ -0,0 +1,350 @@ +@import './theme'; +@import './code'; + +* { + box-sizing: border-box; + margin: 0; +} + +:root { + --user-font-scale: 1rem - 16px; + --max-width: calc(100% - 2rem); +} + +@media (min-width: 50em) { + :root { + --max-width: 48em; + } +} + +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: clamp(2.488rem, 1.9240rem + 1.4100vw, 3.052rem); +} + +h2 { + font-size: clamp(2.074rem, 1.7070rem + 0.9175vw, 2.441rem); +} + +h3 { + font-size: clamp(1.728rem, 1.5030rem + 0.5625vw, 1.953rem); +} + +h4 { + font-size: clamp(1.44rem, 1.3170rem + 0.3075vw, 1.563rem); +} + +h5 { + font-size: clamp(1.2rem, 1.1500rem + 0.1250vw, 1.25rem); +} + +p { + color: var(--theme-text-light); +} + +small, .text_small { + font-size: 0.833rem; +} + +a { + color: var(--theme-accent); + font-weight: 400; + text-underline-offset: 0.08em; + text-decoration: none; + display: inline-flex; + align-items: center; + gap: 0.5rem; +} + +a > code:not([class*="language"]) { + position: relative; + color: var(--theme-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: .85em; + color: inherit; + 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); + margin-left: calc(50vw - var(--padding-inline)); + transform: translateX(-50vw); + + line-height: 1.414; + width: calc(100vw + 4px); + max-width: calc(100% + (var(--padding-inline) * 2)); + overflow-y: hidden; + overflow-x: auto; +} + +@media (min-width: 37.75em) { + pre { + --padding-inline: 1.25rem; + border-radius: 8px; + } +} + +blockquote { + margin: 2rem 0; + padding: 0.5em 1rem; + border-left: 3px solid rgba(0, 0, 0, 0.35); + background-color: rgba(0, 0, 0, 0.05); + border-radius: 0 0.25rem 0.25rem 0; +} + +.flex { + display: flex; + align-items: center; +} + +header button { + background-color: var(--theme-bg); +} +header button:hover, +header button:focus { + 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; + background-color: var(--theme-bg); +} +button:hover { + +} + +#theme-toggle { + display: flex; + align-items: center; + gap: 0.25em; + padding: 0.33em 0.67em; + margin-left: -0.67em; + margin-right: -0.67em; + border-radius: 99em; + background-color: var(--theme-bg); +} +#theme-toggle: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; +} + +nav h4 { + font-weight: 400; + font-size: 1.25rem; + margin: 0; + margin-bottom: 1em; +} + +.edit-on-github, +.header-link { + font-size: 1rem; + padding-left: 1rem; + border-left: 4px solid var(--theme-divider); +} + +.edit-on-github:hover, +.edit-on-github:focus, +.header-link:hover, +.header-link:focus { + color: var(--theme-text-light); + border-left-color: var(--theme-text-lighter); +} + +.header-link:focus-within { + color: var(--theme-text-light); + border-left-color: var(--theme-text-lighter); +} + +.header-link.active { + border-left-color: var(--theme-accent); + color: var(--theme-accent); +} + +.header-link.depth-2 { + font-weight: 600; +} + +.header-link.depth-3 { + padding-left: 2rem; +} +.header-link.depth-4 { + padding-left: 3rem; +} + +.edit-on-github, +.header-link a { + font: inherit; + color: inherit; + text-decoration: none; +} + +.edit-on-github { + margin-top: 2rem; + text-decoration: none; +} +.edit-on-github > * { + text-decoration: none; +} + +.nav-link { + font-size: 1rem; + margin-bottom: 0; + transform: translateX(0); + transition: 120ms transform ease-out; +} + +.nav-link:hover, +.nav-link:focus { + color: var(--theme-text-lighter); + transform: translateX(0.25em); +} + +.nav-link:focus-within { + color: var(--theme-text-lighter); + transform: translateX(0.25em); +} + +.nav-link a { + font: inherit; + color: inherit; + text-decoration: none; +} + +.nav-groups > li + li { + margin-top: 2rem; +} diff --git a/docs-www/public/theme.css b/docs-www/public/theme.css new file mode 100644 index 000000000..d381604c8 --- /dev/null +++ b/docs-www/public/theme.css @@ -0,0 +1,73 @@ +: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-blue: #3894FF; + --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-bg: var(--color-white); + --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-text: var(--color-gray-100); + --theme-code-bg: var(--color-gray-700); +} + +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-400); + --theme-text-lighter: var(--color-gray-600); + --theme-bg: var(--color-black); + --theme-bg-offset: var(--color-gray-900); + --theme-code-inline-bg: var(--color-gray-800); + --theme-code-text: var(--color-gray-200); + --theme-code-bg: var(--color-gray-900); +} + +::selection { + color: var(--theme-accent); + background-color: rgba(var(--theme-accent-rgb), var(--theme-accent-opacity)); +} diff --git a/docs-www/public/theme.js b/docs-www/public/theme.js new file mode 100644 index 000000000..d75d0bf99 --- /dev/null +++ b/docs-www/public/theme.js @@ -0,0 +1,8 @@ +(() => { + 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-www/src/components/ArticleFooter.astro b/docs-www/src/components/ArticleFooter.astro new file mode 100644 index 000000000..8078e2cc3 --- /dev/null +++ b/docs-www/src/components/ArticleFooter.astro @@ -0,0 +1,15 @@ +--- +import AvatarList from './AvatarList.astro'; +--- + +
+ +
+ + diff --git a/docs-www/src/components/AvatarList.astro b/docs-www/src/components/AvatarList.astro new file mode 100644 index 000000000..aafcb371b --- /dev/null +++ b/docs-www/src/components/AvatarList.astro @@ -0,0 +1,74 @@ + + + + + diff --git a/docs-www/src/components/DocSidebar.tsx b/docs-www/src/components/DocSidebar.tsx new file mode 100644 index 000000000..076d460cc --- /dev/null +++ b/docs-www/src/components/DocSidebar.tsx @@ -0,0 +1,61 @@ +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(h2, h3, h4)'); + itemOffsets.current = Array.from(titles).map((title) => ({ + id: title.id, + topOffset: title.getBoundingClientRect().top + window.scrollY, + })); + }; + + const onScroll = () => { + const itemIndex = itemOffsets.current.findIndex((item) => item.topOffset > window.scrollY + window.innerHeight / 3); + if (itemIndex === 0) { + setActiveId(undefined); + } else if (itemIndex === -1) { + setActiveId(itemOffsets.current[itemOffsets.current.length - 1].id); + } else { + setActiveId(itemOffsets.current[itemIndex - 1].id); + } + }; + + getItemOffsets(); + window.addEventListener('resize', getItemOffsets); + window.addEventListener('scroll', onScroll); + + return () => { + window.removeEventListener('resize', getItemOffsets); + window.removeEventListener('scroll', onScroll); + }; + }, []); + + return ( + + ); +}; + +export default DocSidebar; diff --git a/docs-www/src/components/EditOnGithub.tsx b/docs-www/src/components/EditOnGithub.tsx new file mode 100644 index 000000000..f7478934f --- /dev/null +++ b/docs-www/src/components/EditOnGithub.tsx @@ -0,0 +1,26 @@ +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-www/src/components/Note.astro b/docs-www/src/components/Note.astro new file mode 100644 index 000000000..46940ddf8 --- /dev/null +++ b/docs-www/src/components/Note.astro @@ -0,0 +1,49 @@ +--- +export let type = "tip"; +export let title; +--- + + + + diff --git a/docs-www/src/components/SiteSidebar.astro b/docs-www/src/components/SiteSidebar.astro new file mode 100644 index 000000000..7279d9aea --- /dev/null +++ b/docs-www/src/components/SiteSidebar.astro @@ -0,0 +1,20 @@ +--- +import { sidebar } from '../config.ts'; +--- + + diff --git a/docs-www/src/components/ThemeToggle.tsx b/docs-www/src/components/ThemeToggle.tsx new file mode 100644 index 000000000..5a5061c15 --- /dev/null +++ b/docs-www/src/components/ThemeToggle.tsx @@ -0,0 +1,71 @@ +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-www/src/config.ts b/docs-www/src/config.ts new file mode 100644 index 000000000..2c2c5cd07 --- /dev/null +++ b/docs-www/src/config.ts @@ -0,0 +1,12 @@ +export const sidebar = [ + { + text: 'Introduction', + children: [ + { + text: 'What is Astro?', + link: '/' + }, + { text: 'Example', link: '/example' }, + ], + }, +]; diff --git a/docs-www/src/layouts/Main.astro b/docs-www/src/layouts/Main.astro new file mode 100644 index 000000000..37efc2f37 --- /dev/null +++ b/docs-www/src/layouts/Main.astro @@ -0,0 +1,228 @@ +--- +import ArticleFooter from '../components/ArticleFooter.astro'; +import SiteSidebar from '../components/SiteSidebar.astro'; +import ThemeToggle from '../components/ThemeToggle.tsx'; +import DocSidebar from '../components/DocSidebar.tsx'; + +export let content; +const headers = content?.astro?.headers; +let editHref = Astro?.request?.url?.pathname?.slice(1) ?? ''; +if (editHref === '') editHref = `index`; +editHref = `https://github.com/snowpackjs/astro/tree/main/examples/doc/src/pages/${editHref}.md` +--- + + + + {content.title} + + +