-
Notifications
You must be signed in to change notification settings - Fork 188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: set up optimize docs instance and move one doc over #1166
Changes from all commits
590175d
13c4464
4ebd441
81eb4f7
11be3bb
60e21b9
526aaa2
aa52179
8662ecc
e5ba999
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
const versionedLinks = require("./src/mdx/versionedLinks"); | ||
|
||
module.exports = { | ||
title: "Camunda Platform 8", | ||
tagline: "Documentation for all components of Camunda Platform 8", | ||
|
@@ -32,6 +34,16 @@ module.exports = { | |
}, | ||
], | ||
"./static/plugins/bpmn-js", | ||
[ | ||
"@docusaurus/plugin-content-docs", | ||
{ | ||
id: "optimize", | ||
path: "optimize", | ||
routeBasePath: "optimize", | ||
beforeDefaultRemarkPlugins: [versionedLinks], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔗 This configures the optimize docs to use the MDX plugin that interprets link target URLs based on the source file directory. |
||
sidebarPath: require.resolve("./optimize_sidebars.js"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @akeller this is the line I had commented out that caused me to go down a rabbit hole yesterday.........docusaurus wasn't using my sidebars because I wasn't telling docusaurus to use them. 😅 😬 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Funny how that works 😬 |
||
}, | ||
], | ||
], | ||
scripts: [], | ||
themeConfig: { | ||
|
@@ -207,6 +219,7 @@ module.exports = { | |
// Please change this to your repo. | ||
editUrl: | ||
"https://github.com/camunda/camunda-platform-docs/edit/main/", | ||
beforeDefaultRemarkPlugins: [versionedLinks], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔗 This configures the main docs to use the MDX plugin that interprets link target URLs based on the source file directory. |
||
}, | ||
blog: false, | ||
theme: { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Set this prefix based on which version of docs you're viewing | ||
// when generating the Optimize sidebars. | ||
// It will be removed from all generated URLs, so that the version can be | ||
// prepended in one place instead of every single link. | ||
const docsAndVersionUrlPrefix = "/docs/next/"; | ||
|
||
// From an anchor in the sidebar, generates a call to a helper function | ||
// based on the link text and path. See optimize_sidebars.js for what | ||
// this helper function is and how it's used. | ||
function mapToDocsLink(a) { | ||
return `docsComponentsLink("${a.innerText}", "${a.pathname.replace( | ||
docsAndVersionUrlPrefix, | ||
"" | ||
)}"),`; | ||
} | ||
|
||
// From a category in the sidebar, generates sidebar definitions for it and its children. | ||
function buildCategory(li) { | ||
const title = li.querySelector( | ||
":scope > div > .menu__link--sublist" | ||
).innerText; | ||
|
||
const children = Array.from(li.querySelectorAll(":scope > .menu__list > li")); | ||
const childrenMapped = children.map(buildLi); | ||
|
||
return ` | ||
{ | ||
"${title}": [ | ||
${childrenMapped.join("\n")} | ||
], | ||
}, | ||
`; | ||
} | ||
|
||
// From an individual page in the sidebar, generates a sidebar definition. | ||
function buildLink(li) { | ||
const anchor = li.querySelector(":scope > .menu__link"); | ||
return mapToDocsLink(anchor); | ||
} | ||
|
||
// From an item in the sidebar, generates the appropriate definitions. | ||
function buildLi(li) { | ||
if (li.classList.contains("theme-doc-sidebar-item-link")) { | ||
return buildLink(li); | ||
} | ||
|
||
if (li.classList.contains("theme-doc-sidebar-item-category")) { | ||
return buildCategory(li); | ||
} | ||
} | ||
|
||
// The root of the sidebar menu. | ||
const root = document.querySelector(".theme-doc-sidebar-menu"); | ||
|
||
// Generates the sidebar definitions for the entire menu. | ||
function buildSidebars() { | ||
const items = Array.from(root.querySelectorAll(":scope > li")); | ||
|
||
const mappedItems = items.map(buildLi); | ||
|
||
return `{ | ||
Components: [ | ||
${mappedItems.join("\n")} | ||
] | ||
} | ||
`; | ||
} | ||
|
||
// Copies the generated sidebar definitions to the clipboard. | ||
copy(buildSidebars()); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Generating Optimize sidebars | ||
|
||
## Why? | ||
|
||
With the Optimize docs living in their own docusaurus docs instance, we need to synchronize sidebar definitions across both instances. This provides a stable left nav for the user. | ||
|
||
Unfortunately docusaurus instances do not have access to each other's documents, so any links that cross instances need to be defined as URLs instead of document IDs. | ||
|
||
This script crawls the left nav of the site you're viewing, and generates a sidebar definition file full of URL-based links. It needs to be corrected for links that are _within_ the `optimize` docs instance, because it's not smart enough to generate doc-based links for them, but it prevents us from having to manually identify every page title/URL in the main `docs` instance. | ||
|
||
The script is run in the browser dev tools console, and the results are pasted into the `optimize_sidebars.js` file. | ||
|
||
## How? | ||
|
||
1. Visit docs.camunda.io | ||
2. Fully expand the entire left nav | ||
|
||
Docusaurus doesn't emit all levels of the nav on initial render. Nested levels get emitted only when they're viewed (i.e. you expand their parent section). | ||
|
||
The sidebar generation script operates on the DOM. Any levels of the nav that aren't in the DOM yet won't be included in the generated items. | ||
|
||
I do this manually, because it doesn't take long, but you could script this step if you wanted to. | ||
|
||
Tip: you can identify if there are any un-expanded menu categories by querying for them in your browser dev tools console: | ||
|
||
```javascript | ||
> document.querySelectorAll(".menu__link--sublist-caret[aria-expanded=false]").length | ||
⋖ 0 | ||
``` | ||
|
||
If that statement returns any number other than 0, there are unexpanded categories remaining. | ||
|
||
3. Paste the contents of generateOptimizeSidebars.js into your browser dev tools console | ||
|
||
- Make sure the value of `docsAndVersionUrlPrefix` is correct based on the version of docs that you're viewing. This value will be stripped from all generated URLs, so that the `optimize_sidebars.js` file can prepend the correct version in only one place instead of every single link. (This will help us avoid a large find/replace when versioning optimize docs.) | ||
|
||
- The last statement of the script copies the generated sidebars into your clipboard. | ||
|
||
4. Paste the results into the optimize_sidebars.js file | ||
|
||
- The results do not include the statement `module.exports = `, so leave that part in 😅. | ||
|
||
- Make sure the results get formatted, as the script generates an object that does not match prettier's desired format. | ||
|
||
5. Replace/revert any Optimize links that exist within the optimize docs | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I move more and more docs over, this step might become enough of a pain that I figure out a way to make the script do doc-based links for already-moved docs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can always call in back up too if manually moving things gets the job done. I love the automated approach though. |
||
|
||
The script generates URL-based links for _all_ items in the sidebar; we want doc-based links for the Optimize docs. | ||
|
||
#### Example | ||
|
||
The script generated this link for me: | ||
|
||
```javascript | ||
docsComponentsLink( | ||
"What is Optimize?", | ||
"components/optimize/what-is-optimize/" | ||
), | ||
``` | ||
|
||
But I revert this to the doc-based link (in shortcut format): | ||
|
||
```javascript | ||
"what-is-optimize", | ||
``` | ||
|
||
6. Smoke-test the navigation locally | ||
|
||
Note that sidebars files may not be watched by docusaurus's local server. You might need to restart your local server to pick up changes. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ description: "Leverage process data and analyze areas for improvement." | |
--- | ||
|
||
:::note | ||
New to Optimize? Visit our introductory guide to [Optimize](/guides/improve-processes-with-optimize.md) to get started. | ||
New to Optimize? Visit our introductory guide to [Optimize]($docs$/guides/improve-processes-with-optimize/) to get started. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔗 This uses the MDX plugin from #1170 to have the site interpret which version of the main docs to send the user to, based on the location of the source file. |
||
::: | ||
|
||
Camunda Platform 8 is built to handle three key aspects of process automation: | ||
|
@@ -14,7 +14,7 @@ Camunda Platform 8 is built to handle three key aspects of process automation: | |
- Automate | ||
- Improve | ||
|
||
A user can design process flows through our [Modeler](/components/modeler/about-modeler.md). In a production scenario, you can deploy through Desktop Modeler, Web Modeler, or programmatically. A user can use [Tasklist](/components/tasklist/introduction-to-tasklist.md) to review and complete tasks, and [Operate](/components/operate/operate-introduction.md) to view and analyze process instances. | ||
A user can design process flows through our [Modeler]($docs$/components/modeler/about-modeler/). In a production scenario, you can deploy through Desktop Modeler, Web Modeler, or programmatically. A user can use [Tasklist]($docs$/components/tasklist/introduction-to-tasklist/) to review and complete tasks, and [Operate]($docs$/components/operate/operate-introduction) to view and analyze process instances. | ||
|
||
Beyond these design and automate cornerstones lies an important component to leverage our process data and analyze areas for improvement: Optimize. | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔗 This uses the MDX plugin I wrote in (TODO: PR number) to have the site interpret which version of the optimize docs to send the user to, based on the location of the source file.