Skip to content
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

Let sidebar uppercase more than dvc in labels made from slugs #3602

Merged
merged 7 commits into from
May 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions content/docs/sidebar.json
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,6 @@
"slug": "dvclive-with-dvc"
},
{
"label": "ML Frameworks",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the sidebar code automatically uppercases ml and api, these two labels can be taken off.

"slug": "ml-frameworks",
"source": "dvclive/ml-frameworks/index.md",
"children": [
Expand Down Expand Up @@ -667,7 +666,6 @@
]
},
{
"label": "API Reference",
"slug": "api-reference",
"source": "api-reference/index.md",
"children": [
Expand Down
13 changes: 10 additions & 3 deletions plugins/gatsby-theme-iterative-docs/src/utils/shared/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,19 @@
const { titleCase } = require('title-case')
const sidebar = require('../../../sidebar')

const UPPERCASE_KEYWORDS_REGEX = /dvc|cml|api|mlem|ml|ldb/g
const PATH_ROOT = '/doc'
const FILE_ROOT = '/docs/'
const FILE_EXTENSION = '.md'

function dvcTitleCase(slug) {
return titleCase(slug.replace(/dvc/g, 'DVC').replace(/-/g, ' '))
function uppercaseSlugKeywords(slug) {
julieg18 marked this conversation as resolved.
Show resolved Hide resolved
return slug.replace(UPPERCASE_KEYWORDS_REGEX, match => {
return match.toUpperCase()
})
}

function slugTitleCase(slug) {
return titleCase(uppercaseSlugKeywords(slug).replace(/-/g, ' '))
}

function validateRawItem({ slug, source, children, type, url }) {
Expand Down Expand Up @@ -113,7 +120,7 @@ function normalizeItem({ rawItem, parentPath, resultRef, prevRef }) {
return {
path: relativePath ? `${PATH_ROOT}/${relativePath}` : PATH_ROOT,
source: source === false ? false : sourcePath,
label: label ? label : dvcTitleCase(slug),
label: label ? label : slugTitleCase(slug),
tutorials: tutorials || {},
prev,
next: undefined,
Expand Down