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 1 commit
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
16 changes: 13 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,22 @@
const { titleCase } = require('title-case')
const sidebar = require('../../../sidebar')

const uppercaseKeywords = ['dvc', 'cml', 'api', 'ml']
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jorgeorpinel, these are the keywords that will be uppercased. Does the list look good?

Copy link
Member

Choose a reason for hiding this comment

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

let's add MLEM, LDB

Copy link
Contributor Author

Choose a reason for hiding this comment

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

List is now ['dvc', 'cml', 'api', 'mlem', 'ml', 'ldb'] :)

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
let newSlug = slug
uppercaseKeywords.forEach(word => {
julieg18 marked this conversation as resolved.
Show resolved Hide resolved
const regex = new RegExp(String.raw`${word}`, 'g')
newSlug = newSlug.replace(regex, word.toUpperCase())
})
return newSlug
}

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

function validateRawItem({ slug, source, children, type, url }) {
Expand Down Expand Up @@ -113,7 +123,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