Update site to support nightly mode

This commit is contained in:
Ines Montani 2020-07-01 13:03:04 +02:00
parent 5e24b8d481
commit f9a56a6993
13 changed files with 71 additions and 24 deletions

View File

@ -19,6 +19,7 @@ import { ReactComponent as NoIcon } from '../images/icons/no.svg'
import { ReactComponent as NeutralIcon } from '../images/icons/neutral.svg' import { ReactComponent as NeutralIcon } from '../images/icons/neutral.svg'
import { ReactComponent as OfflineIcon } from '../images/icons/offline.svg' import { ReactComponent as OfflineIcon } from '../images/icons/offline.svg'
import { ReactComponent as SearchIcon } from '../images/icons/search.svg' import { ReactComponent as SearchIcon } from '../images/icons/search.svg'
import { ReactComponent as MoonIcon } from '../images/icons/moon.svg'
import classes from '../styles/icon.module.sass' import classes from '../styles/icon.module.sass'
@ -41,6 +42,7 @@ const icons = {
neutral: NeutralIcon, neutral: NeutralIcon,
offline: OfflineIcon, offline: OfflineIcon,
search: SearchIcon, search: SearchIcon,
moon: MoonIcon,
} }
const Icon = ({ name, width, height, inline, variant, className }) => { const Icon = ({ name, width, height, inline, variant, className }) => {

View File

@ -2,7 +2,9 @@ import React, { Fragment } from 'react'
import classNames from 'classnames' import classNames from 'classnames'
import pattern from '../images/pattern_blue.jpg' import pattern from '../images/pattern_blue.jpg'
import patternNightly from '../images/pattern_nightly.jpg'
import patternOverlay from '../images/pattern_landing.jpg' import patternOverlay from '../images/pattern_landing.jpg'
import patternOverlayNightly from '../images/pattern_landing_nightly.jpg'
import logoSvgs from '../images/logos' import logoSvgs from '../images/logos'
import Grid from './grid' import Grid from './grid'
@ -14,9 +16,10 @@ import Link from './link'
import { chunkArray } from './util' import { chunkArray } from './util'
import classes from '../styles/landing.module.sass' import classes from '../styles/landing.module.sass'
export const LandingHeader = ({ style = {}, children }) => { export const LandingHeader = ({ nightly, style = {}, children }) => {
const wrapperStyle = { backgroundImage: `url(${pattern})` } const overlay = nightly ? patternOverlayNightly : patternOverlay
const contentStyle = { backgroundImage: `url(${patternOverlay})`, ...style } const wrapperStyle = { backgroundImage: `url(${nightly ? patternNightly : pattern})` }
const contentStyle = { backgroundImage: `url(${overlay})`, ...style }
return ( return (
<header className={classes.header}> <header className={classes.header}>
<div className={classes.headerWrapper} style={wrapperStyle}> <div className={classes.headerWrapper} style={wrapperStyle}>

View File

@ -5,15 +5,22 @@ import classNames from 'classnames'
import patternBlue from '../images/pattern_blue.jpg' import patternBlue from '../images/pattern_blue.jpg'
import patternGreen from '../images/pattern_green.jpg' import patternGreen from '../images/pattern_green.jpg'
import patternPurple from '../images/pattern_purple.jpg' import patternPurple from '../images/pattern_purple.jpg'
import patternNightly from '../images/pattern_nightly.jpg'
import classes from '../styles/main.module.sass' import classes from '../styles/main.module.sass'
const patterns = { blue: patternBlue, green: patternGreen, purple: patternPurple } const patterns = {
blue: patternBlue,
green: patternGreen,
purple: patternPurple,
nightly: patternNightly,
}
export const Content = ({ Component = 'div', className, children }) => ( export const Content = ({ Component = 'div', className, children }) => (
<Component className={classNames(classes.content, className)}>{children}</Component> <Component className={classNames(classes.content, className)}>{children}</Component>
) )
const Main = ({ sidebar, asides, wrapContent, theme, footer, children }) => { const Main = ({ sidebar, asides, wrapContent, theme, footer, children }) => {
const pattern = patterns[theme]
const mainClassNames = classNames(classes.root, { const mainClassNames = classNames(classes.root, {
[classes.withSidebar]: sidebar, [classes.withSidebar]: sidebar,
[classes.withAsides]: asides, [classes.withAsides]: asides,
@ -23,10 +30,7 @@ const Main = ({ sidebar, asides, wrapContent, theme, footer, children }) => {
<main className={mainClassNames}> <main className={mainClassNames}>
{wrapContent ? <Content Component="article">{children}</Content> : children} {wrapContent ? <Content Component="article">{children}</Content> : children}
{asides && ( {asides && (
<div <div className={classes.asides} style={{ backgroundImage: `url(${pattern}` }} />
className={classes.asides}
style={{ backgroundImage: `url(${patterns[theme]}` }}
/>
)} )}
{footer} {footer}
</main> </main>

View File

@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
<path d="M10.895 7.574c0 7.55 5.179 13.67 11.567 13.67 1.588 0 3.101-0.38 4.479-1.063-1.695 4.46-5.996 7.636-11.051 7.636-6.533 0-11.83-5.297-11.83-11.83 0-4.82 2.888-8.959 7.023-10.803-0.116 0.778-0.188 1.573-0.188 2.39z"></path>
</svg>

After

Width:  |  Height:  |  Size: 322 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 KiB

View File

@ -3,11 +3,13 @@
bottom: 0 bottom: 0
left: 0 left: 0
width: 100% width: 100%
background: var(--color-subtle-light) background: var(--color-back)
z-index: 100 z-index: 100
font: var(--font-size-sm)/var(--line-height-md) var(--font-primary) font: var(--font-size-sm)/var(--line-height-md) var(--font-primary)
text-align: center text-align: center
padding: 1rem padding: 1rem
box-shadow: var(--box-shadow)
color: var(--color-theme)
.warning .warning
--alert-bg: var(--color-yellow-light) --alert-bg: var(--color-yellow-light)

View File

@ -47,6 +47,11 @@
--color-theme-purple-light: hsla(255, 61%, 54%, 0.06) --color-theme-purple-light: hsla(255, 61%, 54%, 0.06)
--color-theme-purple-opaque: hsla(255, 61%, 54%, 0.11) --color-theme-purple-opaque: hsla(255, 61%, 54%, 0.11)
--color-theme-nightly: hsl(257, 99%, 67%)
--color-theme-nightly-dark: hsl(257, 99%, 57%)
--color-theme-nightly-light: hsla(257, 99%, 67%, 0.06)
--color-theme-nightly-opaque: hsla(257, 99%, 67%, 0.11)
// Regular colors // Regular colors
--color-back: hsl(0, 0%, 100%) --color-back: hsl(0, 0%, 100%)
--color-front: hsl(213, 15%, 12%) --color-front: hsl(213, 15%, 12%)
@ -106,6 +111,12 @@
--color-theme-light: var(--color-theme-purple-light) --color-theme-light: var(--color-theme-purple-light)
--color-theme-opaque: var(--color-theme-purple-opaque) --color-theme-opaque: var(--color-theme-purple-opaque)
.theme-nightly
--color-theme: var(--color-theme-nightly)
--color-theme-dark: var(--color-theme-nightly-dark)
--color-theme-light: var(--color-theme-nightly-light)
--color-theme-opaque: var(--color-theme-nightly-opaque)
/* Fonts */ /* Fonts */

View File

@ -22,6 +22,9 @@ $crumb-bar: 2px
& > * & > *
padding: 0 2rem 0.35rem padding: 0 2rem 0.35rem
&:last-child
margin-bottom: 5rem
.label .label
color: var(--color-dark) color: var(--color-dark)
font: bold var(--font-size-lg)/var(--line-height-md) var(--font-secondary) font: bold var(--font-size-lg)/var(--line-height-md) var(--font-secondary)

View File

@ -31,7 +31,7 @@ const Docs = ({ pageContext, children }) => (
theme, theme,
version, version,
} = pageContext } = pageContext
const { sidebars = [], modelsRepo, languages } = site.siteMetadata const { sidebars = [], modelsRepo, languages, nightly } = site.siteMetadata
const isModels = section === 'models' const isModels = section === 'models'
const sidebar = pageContext.sidebar const sidebar = pageContext.sidebar
? { items: pageContext.sidebar } ? { items: pageContext.sidebar }
@ -83,7 +83,7 @@ const Docs = ({ pageContext, children }) => (
{sidebar && <Sidebar items={sidebar.items} pageMenu={pageMenu} slug={slug} />} {sidebar && <Sidebar items={sidebar.items} pageMenu={pageMenu} slug={slug} />}
<Main <Main
section={section} section={section}
theme={theme} theme={nightly ? 'nightly' : theme}
sidebar sidebar
asides asides
wrapContent wrapContent
@ -146,6 +146,7 @@ const query = graphql`
models models
starters starters
} }
nightly
sidebars { sidebars {
section section
items { items {

View File

@ -75,10 +75,23 @@ const scopeComponents = {
InlineCode, InlineCode,
} }
const AlertSpace = () => { const AlertSpace = ({ nightly }) => {
const isOnline = useOnlineStatus() const isOnline = useOnlineStatus()
return ( return (
<> <>
{nightly && (
<Alert
title="You're viewing the pre-release docs."
icon="moon"
closeOnClick={false}
>
The page reflects{' '}
<Link to="https://pypi.org/project/spacy-nightly/">
<InlineCode>spacy-nightly</InlineCode>
</Link>
, not the latest <Link to="https://spacy.io">stable version</Link>.
</Alert>
)}
{!isOnline && ( {!isOnline && (
<Alert title="Looks like you're offline." icon="offline" variant="warning"> <Alert title="Looks like you're offline." icon="offline" variant="warning">
But don't worry, your visited pages should be saved for you. But don't worry, your visited pages should be saved for you.
@ -130,9 +143,10 @@ class Layout extends React.Component {
const { data, pageContext, location, children } = this.props const { data, pageContext, location, children } = this.props
const { file, site = {} } = data || {} const { file, site = {} } = data || {}
const mdx = file ? file.childMdx : null const mdx = file ? file.childMdx : null
const { title, section, sectionTitle, teaser, theme = 'blue', searchExclude } = pageContext
const bodyClass = classNames(`theme-${theme}`, { 'search-exclude': !!searchExclude })
const meta = site.siteMetadata || {} const meta = site.siteMetadata || {}
const { title, section, sectionTitle, teaser, theme = 'blue', searchExclude } = pageContext
const uiTheme = meta.nightly ? 'nightly' : theme
const bodyClass = classNames(`theme-${uiTheme}`, { 'search-exclude': !!searchExclude })
const isDocs = ['usage', 'models', 'api', 'styleguide'].includes(section) const isDocs = ['usage', 'models', 'api', 'styleguide'].includes(section)
const content = !mdx ? null : ( const content = !mdx ? null : (
<MDXProvider components={mdxComponents}> <MDXProvider components={mdxComponents}>
@ -149,7 +163,7 @@ class Layout extends React.Component {
sectionTitle={sectionTitle} sectionTitle={sectionTitle}
bodyClass={bodyClass} bodyClass={bodyClass}
/> />
<AlertSpace /> <AlertSpace nightly={meta.nightly} />
<Navigation <Navigation
title={meta.title} title={meta.title}
items={meta.navigation} items={meta.navigation}
@ -167,11 +181,11 @@ class Layout extends React.Component {
mdxComponents={mdxComponents} mdxComponents={mdxComponents}
/> />
) : ( ) : (
<> <div>
{children} {children}
{content} {content}
<Footer wide /> <Footer wide />
</> </div>
)} )}
</> </>
) )
@ -184,6 +198,7 @@ export const pageQuery = graphql`
query($slug: String!) { query($slug: String!) {
site { site {
siteMetadata { siteMetadata {
nightly
title title
description description
navigation { navigation {

View File

@ -30,8 +30,8 @@ function filterResources(resources, data) {
return sorted.filter(res => (res.category || []).includes(data.id)) return sorted.filter(res => (res.category || []).includes(data.id))
} }
const UniverseContent = ({ content = [], categories, pageContext, location, mdxComponents }) => { const UniverseContent = ({ content = [], categories, theme, pageContext, mdxComponents }) => {
const { theme, data = {} } = pageContext const { data = {} } = pageContext
const filteredResources = filterResources(content, data) const filteredResources = filterResources(content, data)
const activeData = data ? content.find(({ id }) => id === data.id) : null const activeData = data ? content.find(({ id }) => id === data.id) : null
const markdownComponents = { ...mdxComponents, code: InlineCode } const markdownComponents = { ...mdxComponents, code: InlineCode }
@ -302,15 +302,16 @@ const Universe = ({ pageContext, location, mdxComponents }) => (
<StaticQuery <StaticQuery
query={query} query={query}
render={data => { render={data => {
const content = data.site.siteMetadata.universe.resources const { universe, nightly } = data.site.siteMetadata
const categories = data.site.siteMetadata.universe.categories const theme = nightly ? 'nightly' : pageContext.theme
return ( return (
<UniverseContent <UniverseContent
content={content} content={universe.resources}
categories={categories} categories={universe.categories}
pageContext={pageContext} pageContext={pageContext}
location={location} location={location}
mdxComponents={mdxComponents} mdxComponents={mdxComponents}
theme={theme}
/> />
) )
}} }}
@ -323,6 +324,7 @@ const query = graphql`
query UniverseQuery { query UniverseQuery {
site { site {
siteMetadata { siteMetadata {
nightly
universe { universe {
resources { resources {
type type

View File

@ -68,7 +68,7 @@ const Landing = ({ data }) => {
const counts = getCounts(data.languages) const counts = getCounts(data.languages)
return ( return (
<> <>
<LandingHeader> <LandingHeader nightly={data.nightly}>
<LandingTitle> <LandingTitle>
Industrial-Strength Industrial-Strength
<br /> <br />
@ -268,6 +268,7 @@ const landingQuery = graphql`
query LandingQuery { query LandingQuery {
site { site {
siteMetadata { siteMetadata {
nightly
repo repo
languages { languages {
models models