Skip to content

Commit 5d5c43b

Browse files
authored
Merge pull request #99 from AdrianDsg/adriandsg-enhance-contents
fix bugs in TypeScript code, add missing dependency and updater workflow
2 parents e18caf5 + 41e79b4 commit 5d5c43b

File tree

7 files changed

+128
-13
lines changed

7 files changed

+128
-13
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: update json assets
2+
on:
3+
push:
4+
paths:
5+
- .github/workflows/update-json-assets.yaml
6+
7+
# Allows you to run this workflow manually from the Actions tab
8+
workflow_dispatch:
9+
10+
schedule:
11+
# runs on the first day of the month at 04:05AM (UTC)
12+
- cron: "5 4 1 * *"
13+
14+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
15+
concurrency:
16+
group: "updater"
17+
cancel-in-progress: false
18+
19+
jobs:
20+
update-assets:
21+
runs-on: ubuntu-latest
22+
steps:
23+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
24+
- uses: actions/checkout@v4
25+
- uses: actions/setup-node@v4
26+
with:
27+
node-version: latest
28+
cache: yarn
29+
- name: Install
30+
run: yarn install
31+
- name: Build
32+
run: yarn run build
33+
- name: run all downloaders
34+
run: |
35+
ls -lisha out/downloader/
36+
for i in out/downloader/*.js; do
37+
# skipping the syntax downloader
38+
if [[ $i != *"nginx_syntax"* ]]; then
39+
echo "executing 'node $i' ..."
40+
node "$i" || true
41+
fi
42+
done
43+
44+
git add assets/**/*.json
45+
git status
46+
47+
- name: creating the pull request body
48+
id: pr-body
49+
run: |
50+
json_path="assets/**/*.json"
51+
52+
# capturing git diff stats and removing whitespace
53+
diff_shortstat=$(git diff --staged --shortstat "$json_path" | sed -re 's/^[[:blank:]]+|[[:blank:]]+$//g' -e 's/[[:blank:]]+/ /g')
54+
diff_numstat=$(git diff --staged --numstat "$json_path" | sed -re 's/^[[:blank:]]+|[[:blank:]]+$//g' -e 's/[[:blank:]]+/ /g')
55+
56+
pr_body="This pull request has been generated **automatically** to **update** the following files:\n\n\`\`\`bash\n$diff_shortstat\n\n$diff_numstat\n\`\`\`\n"
57+
58+
echo -e "\n----------------------\nThe pull request body:\n----------------------\n"
59+
echo -e "$pr_body"
60+
61+
echo -e "$pr_body" >> $GITHUB_STEP_SUMMARY
62+
63+
echo 'pr_body<<EOF' >> $GITHUB_OUTPUT
64+
echo -e "$pr_body" >> $GITHUB_OUTPUT
65+
echo 'EOF' >> $GITHUB_OUTPUT
66+
- uses: actions/upload-artifact@v4
67+
with:
68+
name: json-assets
69+
path: |
70+
assets/**/*.json
71+
retention-days: 3
72+
# - name: Create Pull Request
73+
# id: cpr
74+
# uses: peter-evans/create-pull-request@v6
75+
# with:
76+
# token: ${{ secrets.GITHUB_TOKEN }}
77+
# add-paths: |
78+
# assets/**/*.json
79+
# commit-message: "chore(assets): update json assets"
80+
# branch: update-json-assets
81+
# delete-branch: true
82+
# base: main
83+
# title: "Update JSON files in assets/"
84+
# body: ${{ steps.pr-body.outputs.pr_body }}
85+
# labels: dependencies
86+
# draft: false

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"rimraf": "^5",
7373
"swc-loader": "^0.2.6",
7474
"turndown": "^7.1.2",
75+
"turndown-plugin-gfm": "^1.0.2",
7576
"typescript": "^5",
7677
"webpack": "^5",
7778
"webpack-cli": "^5"

src/downloader/config_url.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export const httpHeadersWikiURLs = {
2828
de: 'https://de.wikipedia.org/wiki/Liste_der_HTTP-Headerfelder',
2929
en: 'https://en.wikipedia.org/wiki/List_of_HTTP_header_fields',
3030
es: 'https://es.wikipedia.org/wiki/Anexo:Cabeceras_HTTP',
31+
pt: 'https://pt.wikipedia.org/wiki/Lista_de_campos_de_cabe%C3%A7alho_HTTP',
3132
'zh-Hans': 'https://zh.wikipedia.org/zh-cn/HTTP%E5%A4%B4%E5%AD%97%E6%AE%B5',
3233
'zh-Hant-HK': 'https://zh.wikipedia.org/zh-hk/HTTP%E5%A4%B4%E5%AD%97%E6%AE%B5',
3334
'zh-Hant-TW': 'https://zh.wikipedia.org/zh-tw/HTTP%E5%A4%B4%E5%AD%97%E6%AE%B5',

src/downloader/http_headers.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ async function main() {
249249
const output = new JsonFileWriter(manifestFiles.httpHeaders("de"));
250250
const html = await getText("de", baseUrl);
251251
const $ = loadHtml(html);
252-
const handleEnglishRow = ($row: Cheerio<Element>, type: ManifestItemType) => {
252+
const handleGermanRow = ($row: Cheerio<Element>, type: ManifestItemType) => {
253253
const $cols = $row.find("td");
254254
if ($cols.length === 0) return;
255255
const headerNames = normalizeHeaderName($cols.eq(0).text());
@@ -269,7 +269,39 @@ async function main() {
269269
const $rows = element.find("tr");
270270
for (let row = 0; row < $rows.length; row++) {
271271
const $row = $rows.eq(row);
272-
handleEnglishRow($row, ManifestItemType.HttpReqHeader);
272+
handleGermanRow($row, ManifestItemType.HttpReqHeader);
273+
}
274+
}
275+
output.close();
276+
}
277+
278+
// pt
279+
{
280+
const baseUrl = httpHeadersWikiURLs.pt;
281+
const output = new JsonFileWriter(manifestFiles.httpHeaders("pt"));
282+
const html = await getText("pt", baseUrl);
283+
const $ = loadHtml(html);
284+
const handlePortgueseRow = ($row: Cheerio<Element>, type: ManifestItemType) => {
285+
const $cols = $row.find("td");
286+
if ($cols.length === 0) return;
287+
const headerNames = normalizeHeaderName($cols.eq(0).text());
288+
const description = getDescriptionMarkdown($cols.eq(1), baseUrl);
289+
if (!description) print.warn(`header ${headerNames[0]} has no description`);
290+
for (let j = 0; j < headerNames.length; j++) {
291+
const headerName = headerNames[j];
292+
output.writeItem(j === 0 ? [type, headerName, description] : [type, headerName, -1]);
293+
}
294+
};
295+
296+
const $reqH2 = $("h2 #Campos_de_resposta");
297+
assertLength("request fields h2", $reqH2, 1);
298+
const $tables = getNextTables($reqH2.parent(), "h2");
299+
assertLength("request fields table", $tables, 2);
300+
for (const element of $tables) {
301+
const $rows = element.find("tr");
302+
for (let row = 0; row < $rows.length; row++) {
303+
const $row = $rows.eq(row);
304+
handlePortgueseRow($row, ManifestItemType.HttpReqHeader);
273305
}
274306
}
275307
output.close();

src/downloader/lua_openresty.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,9 @@ function processDirectiveElement(
145145
item.desc = item.desc || character;
146146
item.notes.push(character);
147147

148-
// console.log(temp.toString());
149-
// console.log(" --- --- --- --- ")
150-
151148
docsHTML += temp.toString();
152149
}
153150

154-
// console.log(docsHTML);
155-
156151
if (item.def.startsWith("no")) {
157152
item.def = directiveName + " ;";
158153
}
@@ -184,11 +179,6 @@ function processDirectiveElement(
184179
{},
185180
]);
186181

187-
if (directiveName == "server_rewrite_by_lua_block") {
188-
// TODO: needs to be changed remove SVG objects and add required contents (!)
189-
console.log(docsHTML);
190-
}
191-
192182
detailsStream.writeItem([
193183
ManifestItemType.DirectiveDetails,
194184
directiveName,

src/downloader/nginx_directives.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async function main() {
4040
assertLength(`document page title "${titleShouleBe}"`, $title, 1);
4141

4242
const directiveLists = $title.parent().nextAll("ul.compact");
43-
assertLength("length(ul.compact)", directiveLists, 6);
43+
assertLength("length(ul.compact)", directiveLists, 7);
4444

4545
const modules: Array<{ moduleName: string; moduleIndex: number; uri: string }> = [];
4646
directiveLists.each((i, list) => {

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2929,6 +2929,11 @@ tunnel@0.0.6:
29292929
resolved "https://registry.yarnpkg.com/tunnel/-/tunnel-0.0.6.tgz#72f1314b34a5b192db012324df2cc587ca47f92c"
29302930
integrity sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==
29312931

2932+
turndown-plugin-gfm@^1.0.2:
2933+
version "1.0.2"
2934+
resolved "https://registry.yarnpkg.com/turndown-plugin-gfm/-/turndown-plugin-gfm-1.0.2.tgz#6f8678a361f35220b2bdf5619e6049add75bf1c7"
2935+
integrity sha512-vwz9tfvF7XN/jE0dGoBei3FXWuvll78ohzCZQuOb+ZjWrs3a0XhQVomJEb2Qh4VHTPNRO4GPZh0V7VRbiWwkRg==
2936+
29322937
turndown@^7.1.2:
29332938
version "7.1.3"
29342939
resolved "https://registry.yarnpkg.com/turndown/-/turndown-7.1.3.tgz#2890eb76c603e66bf0c9e91526582b563065c57d"

0 commit comments

Comments
 (0)