Skip to content

Commit

Permalink
Feat: add branch display to dev builds (#468)
Browse files Browse the repository at this point in the history
* add branch name for local builds

* update display
  • Loading branch information
rossgalloway authored Sep 22, 2024
1 parent 2c39f04 commit 6b72120
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ yarn-error.log*

.markdownlint.json

.branch-name

# Use yarn.lock
package-lock.json

Expand Down
7 changes: 7 additions & 0 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import math from 'remark-math'
import katex from 'rehype-katex'
import { themes as prismThemes } from 'prism-react-renderer'

const branchName = process.env.BRANCH_NAME || 'unknown'
const isDev = process.env.IS_DEV === 'true'

export default {
title: 'Yearn Docs',
tagline: 'DeFi made simple',
Expand All @@ -17,6 +20,10 @@ export default {
markdown: {
mermaid: true,
},
customFields: {
branchName,
isDev,
},
themes: ['@docusaurus/theme-mermaid'],
themeConfig: {
docs: {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"version": "0.4.3",
"scripts": {
"docusaurus": "docusaurus",
"start": "docusaurus start",
"get-branch-name": "git rev-parse --abbrev-ref HEAD > .branch-name",
"start": "yarn get-branch-name && BRANCH_NAME=$(cat .branch-name) IS_DEV=true docusaurus start",
"build": "docusaurus build",
"swizzle": "docusaurus swizzle",
"deploy": "docusaurus deploy",
Expand Down
27 changes: 27 additions & 0 deletions src/theme/Layout/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react'
import Layout from '@theme-original/Layout'
import useDocusaurusContext from '@docusaurus/useDocusaurusContext'

export default function LayoutWrapper(props) {
const { siteConfig } = useDocusaurusContext()
const { branchName, isDev } = siteConfig.customFields

return (
<>
{isDev && (
<div
style={{
position: 'fixed',
top: 0,
right: 0,
background: 'yellow',
padding: '5px',
}}
>
{branchName}
</div>
)}
<Layout {...props} />
</>
)
}

0 comments on commit 6b72120

Please sign in to comment.