Skip to content
Open

Sync #44

Show file tree
Hide file tree
Changes from 2 commits
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
Empty file.
15 changes: 12 additions & 3 deletions website/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
{
"scripts": {
"examples": "docusaurus-examples",
"start": "docusaurus-start",
"build": "docusaurus-build",
"clean:docs": "rm -r ../docs/sync/*",
"sync:dandelion-apps": "node ./scripts/sync-dandelion-apps.js",
"generate": "npm run clean:docs && npm run sync:dandelion-apps",
"start": "npm run generate && docusaurus-start",
"build": "npm run generate && docusaurus-build",
"publish-gh-pages": "docusaurus-publish",
"write-translations": "docusaurus-write-translations",
"version": "docusaurus-version",
"rename-version": "docusaurus-rename-version"
},
"devDependencies": {
"docusaurus": "^1.9.0"
"docusaurus": "^1.9.0",
"@aragon/docusaurus": "^1.7.3",
"node-fetch": "^2.3.0",
"opn": "^5.3.0",
"prettier": "1.16.4",
"glob": "^7.1.4",
"react-docgen": "^4.1.1"
}
}
28 changes: 28 additions & 0 deletions website/scripts/sync-dandelion-apps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const { syncPages } = require('./sync-util')

const GIT_REF = 'master'
const REPO = '1hive/redemptions-app'

/*
NOTE!
- the contentLocation fields are CASE SENSITIVE
- there needs to be placeholder content in the sync directory before you can run the sync scripts (because the way they're written they overwrite old versions of the docs in that location)
- you need to tell package.json to clear out the old sync directory and run the sync scripts to add new content
- you need to link to the synced docs in sidebars.js
*/

const pages = [

/* Redemptions Overview */
{
destination: 'docs/sync/dandelion/redemptions-overview.md',
id: 'redemptions-overview',
sidebarLabel: 'Redemptions',
title: '1Hive Redemptions App',
contentLocation: 'docs/overview.md',
}
]

const locationReferenceMap = {}

syncPages(pages, locationReferenceMap, GIT_REF, REPO)
55 changes: 55 additions & 0 deletions website/scripts/sync-util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const fetch = require('node-fetch')
const fs = require('fs')

async function syncPages(pages, locationReferenceMap, gitRef, repo) {
Promise.all(
pages.map(page => syncPage(page, locationReferenceMap, gitRef, repo))
)
}

async function syncPage(page, locationReferenceMap, gitRef, repo) {
const {
id,
title,
hideTitle,
sidebarLabel,
contentLocation,
destination,
} = page

const contentURL = `https://raw.githubusercontent.com/${repo}/${gitRef}/${contentLocation}`
const editURL = `https://github.com/${repo}/blob/${gitRef}/${contentLocation}`

const response = await fetch(contentURL)
let remoteText = await response.text()
// Fix the links
if (
locationReferenceMap &&
Object.keys(locationReferenceMap).length !== 0 &&
locationReferenceMap.constructor === Object
) {
remoteText = replaceAll(remoteText, locationReferenceMap)
}

const header = `---
id: ${id}
title: ${title}
custom_edit_url: ${editURL}
sidebar_label: ${sidebarLabel}
hide_title: ${hideTitle || false}
---
<!-- This file is generated by /website/scripts/sync-util.js - changes will be overwritten! -->
`
const result = header.concat('\n').concat(remoteText)
// this script will be run from the website directory => we need to go up one level
fs.writeFileSync(`../${destination}`, result)
}

function replaceAll(string, mapObject) {
const regex = new RegExp(Object.keys(mapObject).join('|'), 'gi')
return string.replace(regex, matched => mapObject[matched])
}

module.exports = {
syncPages,
}
9 changes: 8 additions & 1 deletion website/sidebars.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@
{
"type": "subcategory",
"label": "Dandelion Orgs",
"ids": ["projects/dandelion-orgs/dandelion-overview","projects/dandelion-orgs/redemptions-app","projects/dandelion-orgs/token-request-app" , "projects/dandelion-orgs/lock-app", "projects/dandelion-orgs/delay-app", "projects/dandelion-orgs/voting-dissent-oracle"]
"ids": [
"projects/dandelion-orgs/dandelion-overview",
"sync/dandelion/redemptions-overview",
"projects/dandelion-orgs/token-request-app",
"projects/dandelion-orgs/lock-app",
"projects/dandelion-orgs/delay-app",
"projects/dandelion-orgs/voting-dissent-oracle"
]
},
"projects/commons-license"
]
Expand Down
Loading