-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add Inline code block command linker #70
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3ac26d7
update sidebar to allow multiple sidebars
yathomasi dc7cae5
update command linker to respective url
yathomasi 96218f7
add script and use generated sidebar
yathomasi defda06
add script on build as well
yathomasi a99a660
Merge branch 'main' into inline-code-command-linker
rogermparent 513b3e4
allow using direct url instead of repo details
yathomasi 5b19cd4
Merge branch 'main' into inline-code-command-linker
yathomasi 2a8347c
Merge branch 'main' into inline-code-command-linker
rogermparent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const { | ||
getAllToolsSidebar | ||
} = require('@dvcorg/gatsby-theme-iterative/src/utils/shared/sidebarUtils') | ||
const dvcSidebar = require('./content/docs/sidebar.json') | ||
|
||
const tools = [ | ||
{ | ||
name: 'dvc', | ||
data: dvcSidebar | ||
}, | ||
{ | ||
name: 'cml', | ||
// Or, we can also simply use url to sidebar.json file | ||
// url: 'https://raw.githubusercontent.com/iterative/cml.dev/master/content/docs/sidebar.json' | ||
repo: 'cml.dev', | ||
mainBranch: 'master' | ||
} | ||
] | ||
|
||
getAllToolsSidebar(tools) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
module.exports = require('../../../content/docs/sidebar.json') | ||
module.exports = require('../../../tmp/sidebar.json') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
module.exports = [ | ||
{ | ||
slug: '', | ||
label: 'Home', | ||
source: 'index.md', | ||
icon: 'house' | ||
name: 'dvc', | ||
data: [ | ||
{ | ||
slug: '', | ||
label: 'Home', | ||
source: 'index.md', | ||
icon: 'house' | ||
} | ||
] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
packages/gatsby-theme-iterative/src/utils/shared/sidebarUtils.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
const sidebarArr = require('@dvcorg/gatsby-theme-iterative/sidebar') | ||
const path = require('path') | ||
const fs = require('fs') | ||
const fetch = require('isomorphic-fetch') | ||
|
||
const availableTools = (sidebarArr || []) | ||
.filter(item => item.local) | ||
.map(item => item.name) | ||
|
||
const getToolsBaseUrl = cli => { | ||
if (availableTools.includes(cli)) return '' | ||
switch (cli) { | ||
case 'dvc': | ||
return 'https://dvc.org' | ||
case 'cml': | ||
return 'https://cml.dev' | ||
case 'mlem': | ||
return 'https://mlem.ai' | ||
default: | ||
return '' | ||
} | ||
} | ||
|
||
const getSideBarUrl = (repo, mainBranch = 'main') => { | ||
return `https://raw.githubusercontent.com/iterative/${repo}/${mainBranch}/content/docs/sidebar.json` | ||
} | ||
|
||
const getSidebar = async tool => { | ||
try { | ||
let url = tool.url | ||
if (!url) url = getSideBarUrl(tool.repo, tool.mainBranch) | ||
const res = await fetch(url) | ||
const sidebar = await res.json() | ||
return sidebar | ||
} catch (error) { | ||
console.error( | ||
`Error getting sidebar.json for ${tool.name} from repo ${tool.repo} branch ${tool.mainBranch}` | ||
) | ||
console.error(error) | ||
//skipping | ||
return [] | ||
} | ||
} | ||
|
||
const writeSidebarToFile = allSidebar => { | ||
const dir = 'tmp' | ||
if (!fs.existsSync(dir)) { | ||
fs.mkdirSync(dir) | ||
} | ||
const file = path.join(dir, 'sidebar.json') | ||
const content = JSON.stringify(allSidebar, null, 2) | ||
fs.writeFileSync(file, content) | ||
} | ||
|
||
const getAllToolsSidebar = async tools => { | ||
let allSidebar = [] | ||
|
||
for (const tool of tools) { | ||
if (tool.data) { | ||
tool.local = true | ||
allSidebar = allSidebar.concat(tool) | ||
} else { | ||
const sidebar = await getSidebar(tool) | ||
tool.data = sidebar | ||
allSidebar = allSidebar.concat(tool) | ||
} | ||
} | ||
writeSidebarToFile(allSidebar) | ||
} | ||
|
||
module.exports = { | ||
getToolsBaseUrl, | ||
getSideBarUrl, | ||
getSidebar, | ||
writeSidebarToFile, | ||
getAllToolsSidebar | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Smart idea! We don't need to host the json file on our website if GitHub's already doing the exact same thing.