From fba63f5f09217569509432c058697f057dbada3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20Bl=C3=A4ttermann?= Date: Tue, 20 Dec 2022 17:41:38 +0100 Subject: [PATCH] Minor website fixes (#11974) [ci skip] --- website/README.md | 1 + website/docs/api/morphology.mdx | 10 +- website/docs/api/sentencizer.mdx | 4 +- website/docs/api/token.mdx | 2 +- website/docs/styleguide.mdx | 11 +- website/gatsby-config.js | 28 +- website/gatsby-node.js | 48 +-- website/meta/dynamicMeta.js | 11 + website/meta/site.json | 1 - website/runtime.txt | 2 +- website/src/components/accordion.js | 2 +- website/src/components/code.js | 86 ++--- website/src/components/footer.js | 119 +++---- website/src/components/infobox.js | 2 +- website/src/components/landing.js | 2 +- website/src/components/link.js | 4 +- website/src/components/quickstart.js | 11 +- website/src/components/seo.js | 169 ++++----- website/src/components/typography.js | 6 - website/src/components/util.js | 3 +- website/src/pages/404.js | 29 +- website/src/remark.js | 61 ++++ website/src/styles/aside.module.sass | 7 +- website/src/styles/code.module.sass | 2 +- website/src/styles/embed.module.sass | 6 +- website/src/styles/grid.module.sass | 3 +- website/src/styles/layout.sass | 31 ++ website/src/styles/quickstart.module.sass | 7 +- website/src/styles/search.module.sass | 30 -- website/src/styles/sidebar.module.sass | 9 +- website/src/templates/docs.js | 209 +++++------- website/src/templates/index.js | 121 +------ website/src/templates/models.js | 54 +-- website/src/templates/universe.js | 91 ++--- website/src/widgets/features.js | 125 ++++--- website/src/widgets/landing.js | 89 ++--- website/src/widgets/languages.js | 122 +++---- website/src/widgets/quickstart-install.js | 378 ++++++++++----------- website/src/widgets/quickstart-models.js | 123 +++---- website/src/widgets/quickstart-training.js | 75 ++-- 40 files changed, 844 insertions(+), 1250 deletions(-) create mode 100644 website/meta/dynamicMeta.js create mode 100644 website/src/remark.js diff --git a/website/README.md b/website/README.md index a8fa9c175..1083665ee 100644 --- a/website/README.md +++ b/website/README.md @@ -78,6 +78,7 @@ bit of time. ```yaml ├── docs # the actual markdown content ├── meta # JSON-formatted site metadata +| ├── dynamicMeta.js # At build time generated meta data | ├── languages.json # supported languages and statistical models | ├── sidebars.json # sidebar navigations for different sections | ├── site.json # general site metadata diff --git a/website/docs/api/morphology.mdx b/website/docs/api/morphology.mdx index 565e520b5..080f1c3fe 100644 --- a/website/docs/api/morphology.mdx +++ b/website/docs/api/morphology.mdx @@ -105,11 +105,11 @@ representation. ## Attributes {#attributes} -| Name | Description | -| ------------- | ---------------------------------------------------------------------------------------------------------------------------- | ---------- | -| `FEATURE_SEP` | The [FEATS](https://universaldependencies.org/format.html#morphological-annotation) feature separator. Default is ` | `. ~~str~~ | -| `FIELD_SEP` | The [FEATS](https://universaldependencies.org/format.html#morphological-annotation) field separator. Default is `=`. ~~str~~ | -| `VALUE_SEP` | The [FEATS](https://universaldependencies.org/format.html#morphological-annotation) value separator. Default is `,`. ~~str~~ | +| Name | Description | +| ------------- | ------------------------------------------------------------------------------------------------------------------------------- | +| `FEATURE_SEP` | The [FEATS](https://universaldependencies.org/format.html#morphological-annotation) feature separator. Default is `\|`. ~~str~~ | +| `FIELD_SEP` | The [FEATS](https://universaldependencies.org/format.html#morphological-annotation) field separator. Default is `=`. ~~str~~ | +| `VALUE_SEP` | The [FEATS](https://universaldependencies.org/format.html#morphological-annotation) value separator. Default is `,`. ~~str~~ | ## MorphAnalysis {#morphanalysis tag="class" source="spacy/tokens/morphanalysis.pyx"} diff --git a/website/docs/api/sentencizer.mdx b/website/docs/api/sentencizer.mdx index f5017fbdb..2a1d6a119 100644 --- a/website/docs/api/sentencizer.mdx +++ b/website/docs/api/sentencizer.mdx @@ -38,8 +38,8 @@ how the component should be configured. You can override its settings via the > ``` | Setting | Description | -| ---------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | ------ | -| `punct_chars` | Optional custom list of punctuation characters that mark sentence ends. See below for defaults if not set. Defaults to `None`. ~~Optional[List[str]]~~ | `None` | +| ---------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | +| `punct_chars` | Optional custom list of punctuation characters that mark sentence ends. See below for defaults if not set. Defaults to `None`. ~~Optional[List[str]]~~ | | `overwrite` 3.2 | Whether existing annotation is overwritten. Defaults to `False`. ~~bool~~ | | `scorer` 3.2 | The scoring method. Defaults to [`Scorer.score_spans`](/api/scorer#score_spans) for the attribute `"sents"` ~~Optional[Callable]~~ | diff --git a/website/docs/api/token.mdx b/website/docs/api/token.mdx index 89bd77447..1eef1f4cd 100644 --- a/website/docs/api/token.mdx +++ b/website/docs/api/token.mdx @@ -101,7 +101,7 @@ Check whether an extension has been registered on the `Token` class. | `name` | Name of the extension to check. ~~str~~ | | **RETURNS** | Whether the extension has been registered. ~~bool~~ | -## Token.remove_extension {#remove_extension tag="classmethod" new=""2.0.11""} +## Token.remove_extension {#remove_extension tag="classmethod" new="2.0.11"} Remove a previously registered extension. diff --git a/website/docs/styleguide.mdx b/website/docs/styleguide.mdx index 78b2c1d75..1f0899082 100644 --- a/website/docs/styleguide.mdx +++ b/website/docs/styleguide.mdx @@ -65,16 +65,7 @@ import { Colors, Patterns } from 'widgets/styleguide' ## Typography {#typography} -import { - H1, - H2, - H3, - H4, - H5, - Label, - InlineList, - Comment, -} from 'components/typography' +import { H1, H2, H3, H4, H5, Label, InlineList } from 'components/typography' > #### Markdown > diff --git a/website/gatsby-config.js b/website/gatsby-config.js index 1d919dc33..ca3c75aad 100644 --- a/website/gatsby-config.js +++ b/website/gatsby-config.js @@ -13,16 +13,11 @@ const codeBlocksPlugin = require('./src/plugins/remark-code-blocks.js') // Import metadata const site = require('./meta/site.json') -const sidebars = require('./meta/sidebars.json') -const models = require('./meta/languages.json') -const universe = require('./meta/universe.json') +const { domain, nightly: isNightly, legacy: isLegacy } = site +const { siteUrl } = require('./meta/dynamicMeta') const DEFAULT_TEMPLATE = path.resolve('./src/templates/index.js') -const domain = process.env.BRANCH || site.domain -const siteUrl = `https://${domain}` -const isNightly = site.nightlyBranches.includes(domain) -const isLegacy = site.legacy || !!+process.env.SPACY_LEGACY const favicon = `src/images/icon${isNightly ? '_nightly' : isLegacy ? '_legacy' : ''}.png` const branch = isNightly ? 'develop' : 'master' @@ -34,30 +29,11 @@ const replacements = { SPACY_PKG_FLAGS: isNightly ? ' --pre' : '', } -/** - * Compute the overall total counts of models and languages - */ -function getCounts(langs = []) { - return { - langs: langs.length, - modelLangs: langs.filter(({ models }) => models && !!models.length).length, - models: langs.map(({ models }) => (models ? models.length : 0)).reduce((a, b) => a + b, 0), - } -} - module.exports = { siteMetadata: { ...site, - sidebars, - ...models, - counts: getCounts(models.languages), - universe, - nightly: isNightly, - legacy: isLegacy, - binderBranch: domain, siteUrl, }, - plugins: [ { resolve: `gatsby-plugin-sass`, diff --git a/website/gatsby-node.js b/website/gatsby-node.js index 4a580eb03..caa507db6 100644 --- a/website/gatsby-node.js +++ b/website/gatsby-node.js @@ -4,6 +4,9 @@ const { createFilePath } = require('gatsby-source-filesystem') const DEFAULT_TEMPLATE = path.resolve('./src/templates/index.js') const BASE_PATH = 'docs' const PAGE_EXTENSIONS = ['.md', '.mdx'] +const siteMetadata = require('./meta/site.json') +const universe = require('./meta/universe.json') +const models = require('./meta/languages.json') function replacePath(pagePath) { return pagePath === `/` ? pagePath : pagePath.replace(/\/$/, ``) @@ -26,37 +29,6 @@ exports.createPages = ({ graphql, actions }) => { graphql( ` { - site { - siteMetadata { - sections { - id - title - theme - } - languages { - code - name - models - example - has_examples - } - universe { - resources { - id - title - slogan - } - categories { - label - items { - id - title - description - } - } - } - } - } allFile(filter: { ext: { in: [".md", ".mdx"] } }) { edges { node { @@ -107,8 +79,10 @@ exports.createPages = ({ graphql, actions }) => { reject(result.errors) } - const sectionData = result.data.site.siteMetadata.sections - const sections = Object.assign({}, ...sectionData.map((s) => ({ [s.id]: s }))) + const sections = Object.assign( + {}, + ...siteMetadata.sections.map((s) => ({ [s.id]: s })) + ) /* Regular pages */ @@ -183,8 +157,8 @@ exports.createPages = ({ graphql, actions }) => { }, }) - const universe = result.data.site.siteMetadata.universe.resources - universe.forEach((page) => { + const universeResources = universe.resources + universeResources.forEach((page) => { const slug = `/universe/project/${page.id}` createPage({ @@ -202,7 +176,7 @@ exports.createPages = ({ graphql, actions }) => { }) }) - const universeCategories = result.data.site.siteMetadata.universe.categories + const universeCategories = universe.categories const categories = [].concat.apply( [], universeCategories.map((cat) => cat.items) @@ -227,7 +201,7 @@ exports.createPages = ({ graphql, actions }) => { /* Models */ - const langs = result.data.site.siteMetadata.languages + const langs = models.languages const modelLangs = langs.filter(({ models }) => models && models.length) modelLangs.forEach(({ code, name, models, example, has_examples }, i) => { const slug = `/models/${code}` diff --git a/website/meta/dynamicMeta.js b/website/meta/dynamicMeta.js new file mode 100644 index 000000000..da3031c13 --- /dev/null +++ b/website/meta/dynamicMeta.js @@ -0,0 +1,11 @@ +const site = require('./site.json') + +const domain = process.env.BRANCH || site.domain + +module.exports = { + domain, + siteUrl: `https://${domain}`, + nightly: site.nightlyBranches.includes(domain), + legacy: site.legacy || !!+process.env.SPACY_LEGACY, + binderBranch: domain, +} diff --git a/website/meta/site.json b/website/meta/site.json index fa79d3c69..5dcb89443 100644 --- a/website/meta/site.json +++ b/website/meta/site.json @@ -27,7 +27,6 @@ "indexName": "spacy" }, "binderUrl": "explosion/spacy-io-binder", - "binderBranch": "spacy.io", "binderVersion": "3.4", "sections": [ { "id": "usage", "title": "Usage Documentation", "theme": "blue" }, diff --git a/website/runtime.txt b/website/runtime.txt index 475ba515c..cc1923a40 100644 --- a/website/runtime.txt +++ b/website/runtime.txt @@ -1 +1 @@ -3.7 +3.8 diff --git a/website/src/components/accordion.js b/website/src/components/accordion.js index 00596326f..504f415a5 100644 --- a/website/src/components/accordion.js +++ b/website/src/components/accordion.js @@ -17,7 +17,7 @@ export default function Accordion({ title, id, expanded = false, spaced = false, [classes.hidden]: isExpanded, }) // Make sure accordion is expanded if JS is disabled - useEffect(() => setIsExpanded(expanded), []) + useEffect(() => setIsExpanded(expanded), [expanded]) return (
diff --git a/website/src/components/code.js b/website/src/components/code.js index c4a3640f6..28e3cb5d4 100644 --- a/website/src/components/code.js +++ b/website/src/components/code.js @@ -4,7 +4,6 @@ import classNames from 'classnames' import highlightCode from 'gatsby-remark-prismjs/highlight-code.js' import 'prismjs-bibtex' import rangeParser from 'parse-numeric-range' -import { StaticQuery, graphql } from 'gatsby' import { window } from 'browser-monads' import CUSTOM_TYPES from '../../meta/type-annotations.json' @@ -12,16 +11,20 @@ import { isString, htmlToReact } from './util' import Link, { OptionalLink } from './link' import GitHubCode from './github' import classes from '../styles/code.module.sass' +import siteMetadata from '../../meta/site.json' +import { binderBranch } from '../../meta/dynamicMeta' const WRAP_THRESHOLD = 30 const CLI_GROUPS = ['init', 'debug', 'project', 'ray', 'huggingface-hub'] -export default (props) => ( +const CodeBlock = (props) => (
         
     
) +export default CodeBlock + export const Pre = (props) => { return
{props.children}
} @@ -172,7 +175,7 @@ function formatCode(html, lang, prompt) { .split(' | ') .map((l, i) => convertLine(l, i)) .map((l, j) => ( - + {j !== 0 && | } {l} @@ -268,51 +271,34 @@ export class Code extends React.Component { } } -const JuniperWrapper = ({ Juniper, title, lang, children }) => ( - { - const { binderUrl, binderBranch, binderVersion } = data.site.siteMetadata - const juniperTitle = title || 'Editable Code' - return ( -
-

- {juniperTitle} - - spaCy v{binderVersion} · Python 3 · via{' '} - - Binder - - -

+const JuniperWrapper = ({ Juniper, title, lang, children }) => { + const { binderUrl, binderVersion } = siteMetadata + const juniperTitle = title || 'Editable Code' + return ( +
+

+ {juniperTitle} + + spaCy v{binderVersion} · Python 3 · via{' '} + + Binder + + +

- - {children} - -
- ) - }} - /> -) - -const query = graphql` - query JuniperQuery { - site { - siteMetadata { - binderUrl - binderBranch - binderVersion - } - } - } -` + + {children} + +
+ ) +} diff --git a/website/src/components/footer.js b/website/src/components/footer.js index df19443f2..759db8a7b 100644 --- a/website/src/components/footer.js +++ b/website/src/components/footer.js @@ -1,6 +1,5 @@ import React from 'react' import PropTypes from 'prop-types' -import { StaticQuery, graphql } from 'gatsby' import classNames from 'classnames' import Link from './link' @@ -8,89 +7,55 @@ import Grid from './grid' import Newsletter from './newsletter' import ExplosionLogo from '-!svg-react-loader!../images/explosion.svg' import classes from '../styles/footer.module.sass' +import siteMetadata from '../../meta/site.json' export default function Footer({ wide = false }) { + const { companyUrl, company, footer, newsletter } = siteMetadata return ( - { - const { companyUrl, company, footer, newsletter } = data.site.siteMetadata - return ( -
- - {footer.map(({ label, items }, i) => ( -
-
    -
  • {label}
  • - {items.map(({ text, url }, j) => ( -
  • - - {text} - -
  • - ))} -
-
+
+ + {footer.map(({ label, items }, i) => ( +
+
    +
  • {label}
  • + {items.map(({ text, url }, j) => ( +
  • + + {text} + +
  • ))} -
    -
      -
    • Stay in the loop!
    • -
    • Receive updates about new releases, tutorials and more.
    • -
    • - -
    • -
    -
    - -
    - - © 2016-{new Date().getFullYear()}{' '} - - {company} - - - - - - - Legal / Imprint - -
    -
- ) - }} - /> + +
+ ))} +
+
    +
  • Stay in the loop!
  • +
  • Receive updates about new releases, tutorials and more.
  • +
  • + +
  • +
+
+ +
+ + © 2016-{new Date().getFullYear()}{' '} + + {company} + + + + + + + Legal / Imprint + +
+ ) } Footer.propTypes = { wide: PropTypes.bool, } - -const query = graphql` - query FooterQuery { - site { - siteMetadata { - company - companyUrl - footer { - label - items { - text - url - } - } - newsletter { - user - id - list - } - } - } - } -` diff --git a/website/src/components/infobox.js b/website/src/components/infobox.js index 6df8426b8..d17cbc285 100644 --- a/website/src/components/infobox.js +++ b/website/src/components/infobox.js @@ -29,7 +29,7 @@ export default function Infobox({ {variant !== 'default' && !emoji && ( )} - + {emoji && (