💫 Update website (#3285)
<!--- Provide a general summary of your changes in the title. -->
## Description
The new website is implemented using [Gatsby](https://www.gatsbyjs.org) with [Remark](https://github.com/remarkjs/remark) and [MDX](https://mdxjs.com/). This allows authoring content in **straightforward Markdown** without the usual limitations. Standard elements can be overwritten with powerful [React](http://reactjs.org/) components and wherever Markdown syntax isn't enough, JSX components can be used. Hopefully, this update will also make it much easier to contribute to the docs. Once this PR is merged, I'll implement auto-deployment via [Netlify](https://netlify.com) on a specific branch (to avoid building the website on every PR). There's a bunch of other cool stuff that the new setup will allow us to do – including writing front-end tests, service workers, offline support, implementing a search and so on.
This PR also includes various new docs pages and content.
Resolves #3270. Resolves #3222. Resolves #2947. Resolves #2837.
### Types of change
enhancement
## Checklist
<!--- Before you submit the PR, go over this checklist and make sure you can
tick off all the boxes. [] -> [x] -->
- [x] I have submitted the spaCy Contributor Agreement.
- [x] I ran the tests, and all new and existing tests passed.
- [x] My changes don't require a change to the documentation, or if they do, I've added all required information.
2019-02-17 18:31:19 +00:00
|
|
|
/**
|
|
|
|
* Support titles, line highlights and more for code blocks
|
|
|
|
*/
|
|
|
|
|
|
|
|
const visit = require('unist-util-visit')
|
|
|
|
const parseAttr = require('md-attr-parser')
|
|
|
|
|
|
|
|
const defaultOptions = {
|
|
|
|
defaultPrefix: '###',
|
|
|
|
prefixMap: {
|
|
|
|
javascript: '///',
|
|
|
|
jsx: '///',
|
|
|
|
},
|
|
|
|
languageAliases: {},
|
|
|
|
prompts: ['$'],
|
|
|
|
}
|
|
|
|
|
|
|
|
function remarkCodeBlocks(userOptions = {}) {
|
|
|
|
const options = Object.assign({}, defaultOptions, userOptions)
|
|
|
|
|
|
|
|
function transformer(tree) {
|
|
|
|
visit(tree, 'code', node => {
|
|
|
|
if (node.value) {
|
|
|
|
const langName = node.lang || 'none'
|
|
|
|
const lang = options.languageAliases[langName] || langName
|
|
|
|
const prefix = options.prefixMap[lang] || options.defaultPrefix
|
|
|
|
const lines = node.value.split('\n')
|
|
|
|
let attrs = { lang }
|
|
|
|
const firstLine = lines[0].trim()
|
|
|
|
if (firstLine && firstLine.startsWith(prefix)) {
|
|
|
|
const title = firstLine.slice(prefix.length).trim()
|
|
|
|
attrs.title = title
|
|
|
|
// Check for attributes in title, e.g. {executable="true"}
|
|
|
|
const parsed = title.split(/\{(.*?)\}/)
|
|
|
|
if (parsed.length >= 2 && parsed[1]) {
|
|
|
|
const { prop } = parseAttr(parsed[1])
|
|
|
|
attrs = { ...attrs, ...prop, title: parsed[0].trim(), lang }
|
|
|
|
}
|
|
|
|
// Overwrite the code text with the rest of the lines
|
|
|
|
node.value = lines.slice(1).join('\n')
|
2020-09-12 15:05:10 +00:00
|
|
|
} else if (
|
|
|
|
(firstLine && /^https:\/\/github.com/.test(firstLine)) ||
|
|
|
|
firstLine.startsWith('%%GITHUB_')
|
|
|
|
) {
|
💫 Update website (#3285)
<!--- Provide a general summary of your changes in the title. -->
## Description
The new website is implemented using [Gatsby](https://www.gatsbyjs.org) with [Remark](https://github.com/remarkjs/remark) and [MDX](https://mdxjs.com/). This allows authoring content in **straightforward Markdown** without the usual limitations. Standard elements can be overwritten with powerful [React](http://reactjs.org/) components and wherever Markdown syntax isn't enough, JSX components can be used. Hopefully, this update will also make it much easier to contribute to the docs. Once this PR is merged, I'll implement auto-deployment via [Netlify](https://netlify.com) on a specific branch (to avoid building the website on every PR). There's a bunch of other cool stuff that the new setup will allow us to do – including writing front-end tests, service workers, offline support, implementing a search and so on.
This PR also includes various new docs pages and content.
Resolves #3270. Resolves #3222. Resolves #2947. Resolves #2837.
### Types of change
enhancement
## Checklist
<!--- Before you submit the PR, go over this checklist and make sure you can
tick off all the boxes. [] -> [x] -->
- [x] I have submitted the spaCy Contributor Agreement.
- [x] I ran the tests, and all new and existing tests passed.
- [x] My changes don't require a change to the documentation, or if they do, I've added all required information.
2019-02-17 18:31:19 +00:00
|
|
|
// GitHub URL
|
|
|
|
attrs.github = 'true'
|
|
|
|
}
|
|
|
|
// If it's a bash code block and single line, check for prompts
|
|
|
|
if (lang === 'bash') {
|
|
|
|
const [trueFirstLine, ...trueLines] = node.value.split('\n')
|
|
|
|
for (let prompt of options.prompts) {
|
|
|
|
if (trueFirstLine.startsWith(prompt)) {
|
|
|
|
const content = [
|
|
|
|
trueFirstLine.slice(prompt.length).trim(),
|
|
|
|
...trueLines,
|
|
|
|
]
|
|
|
|
attrs.prompt = prompt
|
|
|
|
node.value = content.join('\n')
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const data = node.data || (node.data = {})
|
|
|
|
const hProps = data.hProperties || (data.hProperties = {})
|
|
|
|
node.data.hProperties = Object.assign({}, hProps, attrs)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return tree
|
|
|
|
}
|
|
|
|
return transformer
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = remarkCodeBlocks
|