Skip to content
This repository was archived by the owner on Aug 26, 2024. It is now read-only.

Commit a64b4ba

Browse files
author
Josh Moore
authored
Merge pull request #515 from tycrek/update-build-process
2 parents dd41a86 + 88a6afc commit a64b4ba

17 files changed

+46
-43
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ on:
44
branches:
55
- master
66
paths: # Only build if these files were modified
7-
- yaml/*.yml
8-
- md/*.md
9-
- _build.js
10-
- _wiki.js
7+
- src/yaml/*.yml
8+
- src/md/*.md
9+
- src/_build.js
10+
- src/_wiki.js
1111
jobs:
1212
build:
1313
runs-on: ubuntu-latest
@@ -20,7 +20,7 @@ jobs:
2020
with:
2121
node-version: 20.x
2222
- name: Build README
23-
run: npm i && node _build.js
23+
run: npm i && node src/_build.js
2424
- name: Commit & Push
2525
# GH_NAME/GH_EMAIL can be any collaborator account with Force Push access
2626
run: |

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
1. **English only** for issues & pull requests.
66
2. **Do not edit README.md!** This file is automatically generated. Instead, use:
7-
- [`yaml/`](https://github.com/tycrek/degoogle/tree/master/yaml) for structured data
8-
- [`md/`](https://github.com/tycrek/degoogle/tree/master/md) for regular text
7+
- [`src/yaml/`](https://github.com/tycrek/degoogle/tree/master/src/yaml) for structured data
8+
- [`src/md/`](https://github.com/tycrek/degoogle/tree/master/src/md) for regular text
99
3. Personal opinions will **not** be considered. Instead, provide detailed links as supporting evidence.
1010
4. **Use the templates** when submitting an Issue or Pull Request. Blank Issues/PRs are not allowed.
1111

_build.js renamed to src/_build.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// Build tool for generating README.md
22

3-
const { EOL } = require('os');
4-
const path = require('path');
53
const fs = require('fs-extra');
6-
const { DateTime } = require('luxon');
4+
const path = require('path');
75
const YAML = require('yaml');
6+
const { EOL } = require('os');
7+
const { DateTime } = require('luxon');
88

99
const BUILD_SECTION = {
1010
header: () => readFile('md/_header.md').replace('{{DATE}}', DateTime.now().toFormat('MMMM dd, yyyy').replace(/ /g, '%20')),
@@ -175,5 +175,5 @@ function generatePublications(pubTitle, filename) {
175175
}
176176

177177
// ! Generate README.md
178-
fs.writeFileSync(path.join(__dirname, 'README.md'), Object.values(BUILD_SECTION).map((section) => section()).join(`${EOL}${EOL}`));
178+
fs.writeFileSync(path.join(process.cwd(), 'README.md'), Object.values(BUILD_SECTION).map((section) => section()).join(`${EOL}${EOL}`));
179179
console.log('Done!');

_wiki.js renamed to src/_wiki.js

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,26 @@
1+
// Build tool for uploading generated README.md to Reddit Wiki
2+
3+
const qs = require('qs');
14
const fs = require('fs-extra');
25
const path = require('path');
36
const fetch = require('node-fetch');
4-
const qs = require('qs');
57
const { DateTime } = require('luxon');
68

7-
// REDDIT_: For authentication with Reddit API. Oauth MUST be used. ID and Secret come from a "script" app type.
8-
const REDDIT_USER = process.env.REDDIT_USER || 'username';
9-
const REDDIT_PASS = process.env.REDDIT_PASS || 'password';
10-
const REDDIT_CLIENT_ID = process.env.REDDIT_CLIENT_ID || 'clientid';
11-
const REDDIT_CLIENT_SECRET = process.env.REDDIT_CLIENT_SECRET || 'clientsecret';
12-
13-
// Initial basic authorization for getting the Oauth token
14-
const BASIC_AUTH = `Basic ${Buffer.from(REDDIT_CLIENT_ID + ':' + REDDIT_CLIENT_SECRET).toString('base64')}`;
15-
16-
// WIKI_: For the Reddit Wiki
17-
const WIKI_SUBREDDIT = 'privacy';
18-
const WIKI_PAGE = 'de-google';
19-
const WIKI_REASON = 'Automated edit from GitHub repo: https://github.com/tycrek/degoogle';
9+
// REDDIT.: For authentication with Reddit API. Oauth MUST be used. ID and Secret come from a "script" app type.
10+
const REDDIT = {
11+
USER: process.env.REDDIT_USER || 'username',
12+
PASS: process.env.REDDIT_PASS || 'password',
13+
CLIENT_ID: process.env.REDDIT_CLIENT_ID || 'clientid',
14+
CLIENT_SECRET: process.env.REDDIT_CLIENT_SECRET || 'clientsecret',
15+
};
2016

2117
// Endpoints for each of our fetches to Reddit
2218
const ENDPOINTS = {
23-
revisions: `https://old.reddit.com/r/${WIKI_SUBREDDIT}/wiki/revisions/${WIKI_PAGE}.json`,
19+
revisions: `https://old.reddit.com/r/privacy/wiki/revisions/de-google.json`,
2420
token: 'https://www.reddit.com/api/v1/access_token',
25-
edit: `https://oauth.reddit.com/r/${WIKI_SUBREDDIT}/api/wiki/edit`
21+
edit: `https://oauth.reddit.com/r/privacy/api/wiki/edit`
2622
};
2723

28-
// Helps POST data be submitted properly
29-
const CONTENT_TYPE = 'application/x-www-form-urlencoded';
30-
3124
// Update the wiki
3225
Promise.all([getLastRevision(), getToken()])
3326
.then(([lastId, token]) => putWiki(lastId, token))
@@ -52,8 +45,15 @@ function getToken() {
5245
return new Promise((resolve, reject) =>
5346
fetch(ENDPOINTS.token, {
5447
method: 'POST',
55-
headers: { 'Authorization': BASIC_AUTH, 'Content-Type': CONTENT_TYPE },
56-
body: qs.stringify({ grant_type: 'password', username: REDDIT_USER, password: REDDIT_PASS })
48+
headers: {
49+
'Authorization': `Basic ${Buffer.from(`${REDDIT.CLIENT_ID}:${REDDIT.CLIENT_SECRET}`).toString('base64')}`,
50+
'Content-Type': 'application/x-www-form-urlencoded'
51+
},
52+
body: qs.stringify({
53+
grant_type: 'password',
54+
username: REDDIT.USER,
55+
password: REDDIT.PASS
56+
})
5757
})
5858
.then((response) => response.json())
5959
.then(({ access_token }) => resolve(access_token))
@@ -69,11 +69,14 @@ function putWiki(lastId, token) {
6969
return new Promise((resolve, reject) =>
7070
fetch(ENDPOINTS.edit, {
7171
method: 'POST',
72-
headers: { 'Authorization': `bearer ${token}`, 'Content-Type': CONTENT_TYPE },
72+
headers: {
73+
'Authorization': `bearer ${token}`,
74+
'Content-Type': 'application/x-www-form-urlencoded'
75+
},
7376
body: qs.stringify({
74-
content: fixContent(fs.readFileSync(path.join(__dirname, 'README.md')).toString()),
75-
page: WIKI_PAGE,
76-
reason: WIKI_REASON,
77+
content: fixContent(fs.readFileSync(path.join(process.cwd(), 'README.md')).toString()),
78+
page: 'de-google',
79+
reason: 'Automated edit from GitHub repo: https://github.com/tycrek/degoogle',
7780
previous: lastId
7881
})
7982
})
@@ -90,12 +93,12 @@ function putWiki(lastId, token) {
9093
* @param {String} content The content in README.md
9194
*/
9295
function fixContent(content) {
93-
// Fix updated timestamp
94-
content = content.replace(/\!\[Updated\](.*?)square\)/g, `#### Updated: ${DateTime.now().toFormat('MMMM dd, yyyy')}`);
96+
return content
9597

96-
// Fix published timestamps
97-
content = content.replace(/\!\[Published\]\(https\:\/\/img\.shields\.io\/badge\//g, '**');
98-
content = content.replace(/-informational\?style=flat-square\)/g, '**');
98+
// Fix updated timestamp
99+
.replace(/\!\[Updated\](.*?)square\)/g, `#### Updated: ${DateTime.now().toFormat('MMMM dd, yyyy')}`)
99100

100-
return content;
101-
} // * If this is highlighted weirdly, it's because of the 'updated timestamp' regex, don't worry about it
101+
// Fix published timestamps
102+
.replace(/\!\[Published\]\(https\:\/\/img\.shields\.io\/badge\//g, '**')
103+
.replace(/-informational\?style=flat-square\)/g, '**');
104+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)