Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GITHUB_OAUTH_CLIENT_ID=
GITHUB_OAUTH_CLIENT_SECRET=
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*
.vscode/settings.json
.vercel
19 changes: 19 additions & 0 deletions api/auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const GITHUB_AUTH_URL = "https://github.com/login/oauth/authorize";
const scopes = "public_repo";

module.exports = (req, res) => {
const clientId = process.env.GITHUB_OAUTH_CLIENT_ID;

if (!clientId) {
res.status(500).json({ error: "missing GITHUB_OAUTH_CLIENT_ID env var" });
return;
}

const redirectUrl =
`${GITHUB_AUTH_URL}?client_id=${clientId}` +
`&scope=${scopes}` +
`&redirect_uri=${process.env.GITHUB_OAUTH_REDIRECT_URI || `${req.headers["x-forwarded-proto"]}://${req.headers.host}/api/callback`}`;

res.writeHead(301, { Location: redirectUrl });
res.end();
};
81 changes: 81 additions & 0 deletions api/callback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
const https = require("https");

function postJSON(url, data) {
return new Promise((resolve, reject) => {
const body = JSON.stringify(data);
const parsed = new URL(url);

const options = {
hostname: parsed.hostname,
path: parsed.pathname,
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Content-Length": Buffer.byteLength(body),
},
};

const req = https.request(options, (res) => {
let chunks = "";
res.on("data", (chunk) => (chunks += chunk));
res.on("end", () => {
try {
resolve(JSON.parse(chunks));
} catch {
reject(new Error(chunks));
}
});
});

req.on("error", reject);
req.write(body);
req.end();
});
}

module.exports = async (req, res) => {
const { code } = req.query;

if (!code) {
res.status(400).json({ error: "missing code parameter" });
return;
}

try {
const data = await postJSON("https://github.com/login/oauth/access_token", {
client_id: process.env.GITHUB_OAUTH_CLIENT_ID,
client_secret: process.env.GITHUB_OAUTH_CLIENT_SECRET,
code,
});

const token = data.access_token;
const escapedToken = JSON.stringify(token);
const provider = "github";

const body = `<!doctype html>
<html>
<body>
<script>
(function() {
var token = ${escapedToken};
var provider = "github";
var payload = JSON.stringify({ token: token, provider: provider });
var message = "authorization:" + provider + ":success:" + payload;

function receiveMessage(e) {
window.opener.postMessage(message, e.origin);
}

window.addEventListener("message", receiveMessage, false);
window.opener.postMessage("authorizing:" + provider, "*");
})();
</script>
</body>
</html>`;

res.status(200).send(body);
} catch (err) {
res.status(500).json({ error: err.message });
}
};
84 changes: 84 additions & 0 deletions static/admin/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
backend:
name: github
repo: ArbitrumFoundation/docs
branch: main
auth_endpoint: /api/auth

logo_url: /img/AF_vertical_stack.png
publish_mode: editorial_workflow
media_folder: static/img
public_folder: /img

collections:
- name: governance-pages
label: Governance Pages
folder: docs
create: true
extension: md
slug: "{{slug}}"
fields:
- { name: id, label: ID, widget: string }
- { name: title, label: Title, widget: string }
- { name: sidebar_label, label: Sidebar Label, widget: string }
- { name: description, label: Description, widget: text }
- { name: dao_author, label: Author, widget: string, required: false }
- { name: dao_sme, label: Subject Matter Expert, widget: string, required: false }
- { name: body, label: Body, widget: markdown }

- name: how-tos
label: How-to Guides
folder: docs/how-tos
create: true
extension: md
slug: "{{slug}}"
fields:
- { name: id, label: ID, widget: string }
- { name: title, label: Title, widget: string }
- { name: sidebar_label, label: Sidebar Label, widget: string }
- { name: description, label: Description, widget: text }
- { name: dao_author, label: Author, widget: string, required: false }
- { name: dao_sme, label: Subject Matter Expert, widget: string, required: false }
- { name: body, label: Body, widget: markdown }

- name: concepts
label: Governance Concepts
folder: docs/concepts
create: true
extension: md
slug: "{{slug}}"
fields:
- { name: id, label: ID, widget: string }
- { name: title, label: Title, widget: string }
- { name: sidebar_label, label: Sidebar Label, widget: string }
- { name: description, label: Description, widget: text }
- { name: dao_author, label: Author, widget: string, required: false }
- { name: dao_sme, label: Subject Matter Expert, widget: string, required: false }
- { name: body, label: Body, widget: markdown }

- name: bold-economics
label: BoLD Economics Guides
folder: docs/arbitrum-bold-economics
create: true
extension: md
slug: "{{slug}}"
fields:
- { name: id, label: ID, widget: string }
- { name: title, label: Title, widget: string }
- { name: sidebar_label, label: Sidebar Label, widget: string }
- { name: description, label: Description, widget: text }
- { name: dao_author, label: Author, widget: string, required: false }
- { name: dao_sme, label: Subject Matter Expert, widget: string, required: false }
- { name: body, label: Body, widget: markdown }

- name: foundational-documents
label: Foundational Documents
folder: docs/foundational-documents
create: true
extension: md
slug: "{{slug}}"
fields:
- { name: id, label: ID, widget: string }
- { name: title, label: Title, widget: string }
- { name: sidebar_label, label: Sidebar Label, widget: string, required: false }
- { name: description, label: Description, widget: text, required: false }
- { name: body, label: Body, widget: markdown }
130 changes: 130 additions & 0 deletions static/admin/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="robots" content="noindex" />
<title>Arbitrum Governance Docs CMS</title>
<link rel="icon" href="/img/favicon.ico" />
<style>
:root {
--arb-blue: #12AAFF;
--arb-dark: #213147;
--arb-light-blue: #9DCCED;
--arb-link: #007bdd;
}

body {
font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

#nc-root > section {
background: var(--arb-dark) !important;
}

#nc-root > section > span > img {
max-width: 200px !important;
display: block !important;
margin: 0 auto !important;
}

#nc-root > section button {
background: var(--arb-blue) !important;
color: #fff !important;
border: none !important;
border-radius: 2px !important;
font-weight: 600 !important;
padding: 12px 32px !important;
font-size: 15px !important;
transition: opacity 0.2s !important;
}

#nc-root > section button:hover {
opacity: 0.9 !important;
}

header {
background: var(--arb-dark) !important;
}

header a {
color: #fff !important;
}

header [class*="AppHeader"] {
background: var(--arb-dark) !important;
}

[class*="ToolbarButton"]:not([class*="Published"]) {
color: var(--arb-dark) !important;
}

a[href="#/collections"],
a[href="#/workflow"],
a[href="#/media"] {
color: var(--arb-light-blue) !important;
font-weight: 600 !important;
}

a[href="#/collections"]:hover,
a[href="#/workflow"]:hover,
a[href="#/media"]:hover {
color: #fff !important;
}

[class*="SidebarNavList"] a {
color: var(--arb-dark) !important;
}

[class*="SidebarNavList"] a:hover,
[class*="SidebarNavList"] a[class*="active"] {
color: var(--arb-blue) !important;
font-weight: 600 !important;
}

button[class*="PublishButton"],
button[class*="ToolbarButton"] {
background: var(--arb-blue) !important;
color: #fff !important;
border: none !important;
border-radius: 2px !important;
}

button[class*="SaveButton"],
button[class*="PublishButton"]:hover {
opacity: 0.9 !important;
}

[class*="EntryListing"] a {
border-left: 3px solid transparent !important;
}

[class*="EntryListing"] a:hover {
border-left-color: var(--arb-blue) !important;
}

[class*="SearchInput"] {
border-radius: 2px !important;
}

[class*="SearchInput"]:focus {
border-color: var(--arb-blue) !important;
}
</style>
<script src="https://unpkg.com/js-yaml@4.1.0/dist/js-yaml.min.js"></script>
</head>
<body>
<script>window.CMS_MANUAL_INIT = true;</script>
<script src="https://unpkg.com/decap-cms@^3.0.0/dist/decap-cms.js"></script>
<script>
fetch("/admin/config.yml")
.then(function(r) { return r.text(); })
.then(function(yml) {
var config = window.jsyaml.load(yml);
config.backend.base_url = window.location.origin;
config.load_config_file = false;
window.CMS.init({ config: config });
});
</script>
</body>
</html>
Binary file added static/img/AF_vertical_stack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion vercel.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@
"source": "/",
"destination": "/gentle-intro-dao-governance"
}
]
],
"functions": {
"api/*.js": {
"memory": 128
}
}
}