Skip to content

Commit

Permalink
Let sidebar uppercase more than dvc in labels made from slugs (#3602)
Browse files Browse the repository at this point in the history
* Update sidebar label creation code
* Let sidebar uppercase more than `dvc` in labels made from slugs

* Add more keywords

* fix typo

* Use only one large regex

* Optimize function

* Just use regex

* Remove unneeded variable
  • Loading branch information
julieg18 authored May 30, 2022
1 parent 9c99a56 commit fcc5ef2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
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",
"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) {
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

0 comments on commit fcc5ef2

Please sign in to comment.