Skip to content

Commit

Permalink
chore: update docusaurus template
Browse files Browse the repository at this point in the history
Signed-off-by: aeneasr <[email protected]>
  • Loading branch information
aeneasr committed Apr 23, 2021
1 parent 27b656a commit 408fa61
Show file tree
Hide file tree
Showing 6 changed files with 15,009 additions and 21,428 deletions.
111 changes: 73 additions & 38 deletions docs/contrib/sidebar.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,9 @@
const config = require('./config.js')
const fs = require('fs')
const path = require('path')

const projects = [
{
slug: 'kratos',
name: 'ORY Kratos'
},
{
slug: 'hydra',
name: 'ORY Hydra'
},
{
slug: 'oathkeeper',
name: 'ORY Oathkeeper'
},
{
slug: 'keto',
name: 'ORY Keto'
}
].filter((item) => config.projectSlug !== item.slug)
const request = require('sync-request')
const parser = require('parser-front-matter')
const base = require(path.join(__dirname, 'sidebar.json'))

let sidebar = {
Welcome: ['index']
Expand All @@ -30,26 +14,77 @@ if (fs.existsSync(cn)) {
sidebar = require(cn)
}

projects.forEach((item) => {
sidebar[item.name] = [
{
type: 'link',
label: 'Home',
href: `https://www.ory.sh/${item.slug}`
},
{
type: 'link',
label: 'Docs',
href: `https://www.ory.sh/${item.slug}/docs`
},
{
type: 'link',
label: 'GitHub',
href: `https://github.com/ory/${item.slug}`
const toHref = (slug, node) => {
if (node !== null && typeof node === 'object') {
if (node.type) {
if (node.type === 'category') {
return {
...node,
items: node.items.map((n) => toHref(slug, n))
}
}
return node
}
]
})

Object.entries(node).forEach(([key, value]) => {
node[key] = toHref(slug, value)
})
return node
} else if (Array.isArray(node)) {
return node.map((value) => {
return toHref(slug, value)
})
}

let res = request(
'GET',
`https://raw.githubusercontent.com/ory/${slug}/new-doc-nav/docs/docs/${node}.mdx`
)
if (res.statusCode === 404) {
res = request(
'GET',
`https://raw.githubusercontent.com/ory/${slug}/new-doc-nav/docs/docs/${node}.md`
)
}

const fm = parser.parseSync(res.getBody().toString())

return {
label: fm.data.title,
type: 'link',
href: `https://www.ory.sh/${slug}/docs/next/${fm.data.slug || node}`
}
}

const resolveRefs = (node) => {
if (node !== null && typeof node == 'object') {
if (node['$slug']) {
const slug = node['$slug']
if (slug === config.projectSlug) {
return sidebar
}

const res = request(
'GET',
`https://raw.githubusercontent.com/ory/${slug}/new-doc-nav/docs/sidebar.json`
)
const items = JSON.parse(res.getBody().toString())

return toHref(slug, items)
}

Object.entries(node).forEach(([key, value]) => {
node[key] = resolveRefs(value)
})
return node
}
return node
}

const result = resolveRefs(base)

console.log(JSON.stringify(result))

module.exports = {
docs: sidebar
docs: resolveRefs(result)
}
27 changes: 27 additions & 0 deletions docs/contrib/sidebar.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"Developer Documentation": {
"$slug": "docs"
},
"Open Source Documentation": [
{
"Ory Kratos": {
"$slug": "kratos"
}
},
{
"Ory Keto": {
"$slug": "keto"
}
},
{
"Ory Hydra": {
"$slug": "hydra"
}
},
{
"Ory Oathkeeper": {
"$slug": "oathkeeper"
}
}
]
}
5 changes: 5 additions & 0 deletions docs/contrib/theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@
padding: 8px;
margin: 32px;
}

.menu__link[href*="https://"]:after
{
display: none !important;
}
30 changes: 14 additions & 16 deletions docs/docusaurus.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const config = require('./contrib/config.js')
const fs = require('fs')

const githubRepoName =
config.projectSlug === 'ecosystem' ? 'docs' : config.projectSlug
Expand All @@ -7,14 +8,8 @@ const baseUrl = config.baseUrl ? config.baseUrl : `/${config.projectSlug}/docs/`

const links = [
{
to: '/',
activeBasePath: baseUrl,
label: `Docs`,
position: 'left'
},
{
href: 'https://www.ory.sh/docs',
label: 'Ecosystem',
to: 'https://www.ory.sh/',
label: `Home`,
position: 'left'
},
{
Expand All @@ -25,20 +20,26 @@ const links = [
{
href: `https://github.com/ory/${githubRepoName}/discussions`,
label: 'Discussions',
position: 'left'
position: 'right'
},
{
href: 'https://www.ory.sh/chat',
label: 'Chat',
position: 'left'
label: 'Slack',
position: 'right'
},
{
href: `https://github.com/ory/${githubRepoName}`,
label: 'GitHub',
position: 'left'
position: 'right'
}
]

const customCss = [require.resolve('./contrib/theme.css')]

if (fs.existsSync('./src/css/theme.css')) {
customCss.push(require.resolve('./src/css/theme.css'))
}

module.exports = {
title: config.projectName,
tagline: config.projectTagLine,
Expand Down Expand Up @@ -144,10 +145,7 @@ module.exports = {
[
'@docusaurus/theme-classic',
{
customCss:
config.projectSlug === 'docusaurus-template'
? require.resolve('./contrib/theme.css')
: require.resolve('./src/css/theme.css')
customCss
}
],
'@docusaurus/theme-search-algolia'
Expand Down
Loading

0 comments on commit 408fa61

Please sign in to comment.