💫 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 21:31:19 +03:00
|
|
|
/**
|
|
|
|
* Check the tree for headlines of a certain depth and wrap the headline and
|
|
|
|
* all content up to the next headline in a section.
|
|
|
|
* Based on: https://github.com/luhmann/tufte-markdown
|
|
|
|
*/
|
|
|
|
|
2022-11-21 20:08:43 +03:00
|
|
|
import { visit } from 'unist-util-visit'
|
💫 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 21:31:19 +03:00
|
|
|
|
|
|
|
const defaultOptions = {
|
|
|
|
element: 'section',
|
|
|
|
prefix: 'section-',
|
|
|
|
depth: 2,
|
|
|
|
slugify: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
function remarkWrapSection(userOptions = {}) {
|
|
|
|
const options = Object.assign({}, defaultOptions, userOptions)
|
|
|
|
|
|
|
|
function transformer(tree) {
|
|
|
|
const headingsMap = []
|
|
|
|
const newTree = []
|
|
|
|
|
2022-12-19 18:18:19 +03:00
|
|
|
visit(tree, 'import', (node) => {
|
💫 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 21:31:19 +03:00
|
|
|
// For compatibility with MDX / gatsby-mdx, make sure import nodes
|
|
|
|
// are not moved further down into children (which means they're not
|
|
|
|
// recognized and interpreted anymore). Add them to the very start
|
|
|
|
// of the tree.
|
|
|
|
newTree.push(node)
|
|
|
|
})
|
|
|
|
|
|
|
|
visit(tree, 'heading', (node, index) => {
|
|
|
|
if (node.depth === options.depth) {
|
|
|
|
const data = node.data || (node.data = {})
|
|
|
|
const hProps = data.hProperties || (data.hProperties = {})
|
|
|
|
headingsMap.push({ index, id: hProps.id })
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
if (headingsMap.length) {
|
|
|
|
for (let index = 0; index <= headingsMap.length; index++) {
|
|
|
|
const sectionStartIndex = index === 0 ? 0 : headingsMap[index - 1].index
|
|
|
|
const sectionEndIndex =
|
|
|
|
index === headingsMap.length ? tree.children.length : headingsMap[index].index
|
|
|
|
const children = tree.children
|
|
|
|
.slice(sectionStartIndex, sectionEndIndex)
|
2022-12-19 18:18:19 +03:00
|
|
|
.filter((node) => node.type !== 'import')
|
💫 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 21:31:19 +03:00
|
|
|
|
|
|
|
if (children.length) {
|
|
|
|
const headingId = index === 0 ? 0 : headingsMap[index - 1].id
|
|
|
|
const sectionId = headingId ? options.prefix + headingId : undefined
|
|
|
|
const wrapperNode = {
|
2022-11-21 19:44:27 +03:00
|
|
|
type: 'section',
|
💫 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 21:31:19 +03:00
|
|
|
children,
|
|
|
|
data: { hName: options.element, hProperties: { id: sectionId } },
|
|
|
|
}
|
|
|
|
newTree.push(wrapperNode)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tree.children = newTree
|
|
|
|
}
|
|
|
|
return tree
|
|
|
|
}
|
|
|
|
return transformer
|
|
|
|
}
|
|
|
|
|
2022-11-21 19:36:29 +03:00
|
|
|
export default remarkWrapSection
|