Skip to content

Commit

Permalink
chore: update docusaurus template
Browse files Browse the repository at this point in the history
Signed-off-by: aeneasr <aeneasr@users.noreply.github.com>
  • Loading branch information
aeneasr committed Mar 19, 2021
1 parent 6806865 commit 4b595e8
Show file tree
Hide file tree
Showing 7 changed files with 19,919 additions and 35 deletions.
10 changes: 8 additions & 2 deletions docs/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ module.exports = {
},
announcementBar: {
id: 'supportus',
content: `Sign up for <a href="${config.newsletter}">important security announcements</a> and if you like ${config.projectName} give it a ⭐️ on <a target="_blank" rel="noopener noreferrer" href="https://github.com/ory/${githubRepoName}">GitHub</a>!`
content:
config.projectSlug === 'docs'
? `Sign up for <a href="${config.newsletter}">important security announcements</a> and if you like the ${config.projectName} give us some ⭐️ on <a target="_blank" rel="noopener noreferrer" href="https://github.com/ory">GitHub</a>!`
: `Sign up for <a href="${config.newsletter}">important security announcements</a> and if you like ${config.projectName} give it a ⭐️ on <a target="_blank" rel="noopener noreferrer" href="https://github.com/ory/${githubRepoName}">GitHub</a>!`
},
algolia: {
apiKey: '8463c6ece843b377565726bb4ed325b0',
Expand All @@ -73,7 +76,10 @@ module.exports = {
alt: config.projectName,
src: `img/logo-${config.projectSlug}.svg`,
srcDark: `img/logo-${config.projectSlug}.svg`,
href: `https://www.ory.sh/${config.projectSlug}`
href:
config.projectSlug === 'docs'
? `https://www.ory.sh`
: `https://www.ory.sh/${config.projectSlug}`
},
items: [
...links,
Expand Down
19,693 changes: 19,664 additions & 29 deletions docs/package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"prettierTarget": "{docs/**,docs,scripts,static,contrib,src,src/**}/*.{md,mdx,json,js,css,html}|*.{js,md}"
},
"scripts": {
"gen": "npm run widdershins && cd .. && node ./docs/scripts/fix-api.js ./docs/docs/reference/api.mdx && node ./docs/scripts/config.js docs/config.js",
"gen": "npm run widdershins && cd .. && node ./docs/scripts/fix-api.js ./docs/docs/reference/api.mdx && node ./docs/scripts/config.js docs/config.js && node ./docs/scripts/gen-faq.js",
"docusaurus": "docusaurus",
"widdershins": "widdershins -u .widdershins/templates -e .widdershins/config.json ../spec/api.json -o ./docs/reference/api.mdx",
"start": "docusaurus start",
Expand Down Expand Up @@ -55,6 +55,7 @@
"ramda": "0.27.1",
"raw-loader": "4.0.2",
"remark-admonitions": "1.2.1",
"remarkable": "2.0.1",
"widdershins": "4.0.1",
"yaml": "1.8.3"
}
Expand Down
105 changes: 105 additions & 0 deletions docs/scripts/gen-faq.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// gen-faq.js
// generates faq.mdx and faq.module.css from the contents of faq.yaml. See https://github.com/ory/kratos/pull/1039.
const fs = require('fs')
const yaml = require('js-yaml')
const { Remarkable } = require('remarkable')
const path = require('path')
const yamlPath = path.resolve('./docs/faq.yaml')
const prettier = require('prettier')
const prettierStyles = require('ory-prettier-styles')
const config = require('../contrib/config.js')

// Generating FAQ.mdx

if (!fs.existsSync(yamlPath)) {
//file exists
console.warn('faq.yaml File does not exists, skipping generating FAQ')
return 0
}

const faqYaml = fs.readFileSync(yamlPath, 'utf8')
const faq = yaml.load(faqYaml)

const tags = Array.from(new Set(faq.map(({ tags }) => tags).flat(1)))

// which project are we running in?
const project = config.projectSlug

let markdownPage = `---
id: faq
title: Frequently Asked Questions (FAQ)
---
<!-- This file is generated. Please edit /docs/faq.yaml or /docs/scripts/gen-faq.js instead. Changes will be overwritten otherwise -->
import {Question, FaqTags} from '@theme/Faq'
<FaqTags tags={${JSON.stringify(tags)}} initiallyDisabled={[${JSON.stringify(
project
)}]}/>
<br/><br/>
`
md = new Remarkable()
faq.forEach((el) => {
markdownPage += `<Question tags={${JSON.stringify(el.tags)}}>\n`
markdownPage += `${el.tags
.map((tag) => {
return '#' + tag
})
.join(' ')}
`
markdownPage += md.render(`**Q**: ${el.q}`)
markdownPage += md.render(`**A**: ${el.a}`)
if (el.context) {
markdownPage += md.render(`context: ${el.context}`)
}
markdownPage += `</Question>
<br/>
`
})

fs.writeFileSync(
path.resolve('./docs/docs/faq.mdx'),
prettier.format(markdownPage, { ...prettierStyles, parser: 'mdx' })
)

// Generating faq.module.css
const tagList = Array.from(
new Set(
faq
.map((el) => {
return el.tags
})
.flat(1)
)
)

let generatedCSS = `
.selected {
background-color: #ffba00;
}
div.question {
display: none;
}
`

tagList.forEach((tag) => {
generatedCSS += `
li.selected.${tag} {
color:red;
}
li.selected.${tag}~.question.${tag} {
display: inline;
}
`
})

fs.writeFileSync(
'./docs/src/theme/faq.gen.module.css',
prettier.format(generatedCSS, { ...prettierStyles, parser: 'css' })
)
6 changes: 3 additions & 3 deletions docs/src/theme/CodeFromRemote.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const transform = ({ startAt, endAt }) => (content) => {
}

const CodeFromRemote = (props) => {
const { src } = props
const { src, title } = props
const [content, setContent] = useState('')

useEffect(() => {
Expand All @@ -86,11 +86,11 @@ const CodeFromRemote = (props) => {
}, [])

const lang = `language-${detectLanguage(src)}`
const title = `title="${findPath(src)}"`
const metaString = `title="${title || findPath(src)}"`

return (
<div className={styles.container}>
<CodeBlock metastring={title} className={lang} children={content} />
<CodeBlock metastring={metaString} className={lang} children={content} />
</div>
)
}
Expand Down
54 changes: 54 additions & 0 deletions docs/src/theme/Faq.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React, { useState } from 'react'
import cn from 'classnames'
import styles from './faq.module.css'
import genStyle from './faq.gen.module.css'

const Question = ({ children, tags }) => (
<div className={cn(genStyle.question, ...tags.map((tag) => genStyle[tag]))}>
{children}
</div>
)

const TagButton = ({ tag, isSelected, children, toggleSelected }) => (
<li
className={cn(
{ [genStyle.selected]: isSelected },
genStyle[tag],
styles.pills,
styles.pills__item,
{ [styles['pills__item--active']]: isSelected }
)}
onClick={toggleSelected}
>
{children}
</li>
)

const FaqTags = ({ tags, initiallyDisabled }) => {
const [selectedTags, setSelectedTags] = useState(
tags.filter((t) => !initiallyDisabled.includes(t))
)

return (
<>
{tags.map((tag) => (
<TagButton
key={tag}
tag={tag}
isSelected={selectedTags.find((t) => t === tag)}
toggleSelected={() => {
if (selectedTags.find((t) => t === tag)) {
setSelectedTags(selectedTags.filter((t) => t !== tag))
} else {
setSelectedTags([...selectedTags, tag])
}
}}
>
#{tag}
</TagButton>
))}
</>
)
}

export { FaqTags, Question }
83 changes: 83 additions & 0 deletions docs/src/theme/faq.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
.pills,
.tabs {
font-weight: var(--ifm-font-weight-bold);
}
.pills {
padding-left: 0;
}
.pills__item {
border-radius: 0.5rem;
cursor: pointer;
display: inline-block;
padding: 0.25rem 1rem;
transition: background var(--ifm-transition-fast)
var(--ifm-transition-timing-default);
}
.pills__item--active {
background: var(--ifm-pills-color-background-active);
color: var(--ifm-pills-color-active);
}
.pills__item:not(.pills__item--active):hover {
background-color: var(--ifm-pills-color-background-active);
}
.pills__item:not(:first-child) {
margin-left: var(--ifm-pills-spacing);
}
.pills__item:not(:last-child) {
margin-right: var(--ifm-pills-spacing);
}
.pills--block {
display: flex;
justify-content: stretch;
}
.pills--block .pills__item {
flex-grow: 1;
text-align: center;
}
.tabs {
display: flex;
overflow-x: auto;
color: var(--ifm-tabs-color);
margin-bottom: 0;
padding-left: 0;
}
.tabs__item {
border-bottom: 3px solid transparent;
border-radius: var(--ifm-global-radius);
cursor: pointer;
display: inline-flex;
padding: var(--ifm-tabs-padding-vertical) var(--ifm-tabs-padding-horizontal);
margin: 0;
transition: background-color var(--ifm-transition-fast)
var(--ifm-transition-timing-default);
}
.tabs__item--active {
border-bottom-color: var(--ifm-tabs-color-active);
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
color: var(--ifm-tabs-color-active);
}
.tabs__item:hover {
background-color: var(--ifm-hover-overlay);
}
.tabs--block {
justify-content: stretch;
}
.tabs--block .tabs__item {
flex-grow: 1;
justify-content: center;
}

p {
margin-bottom: 0px;
}

.selected {
background-color: #ffba00;
}

div.question {
display: none;
}

@import 'faq.module.gen.css';

0 comments on commit 4b595e8

Please sign in to comment.