Skip to content

Commit

Permalink
feat: add portuegese version of http headers
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianDsg authored Apr 25, 2024
1 parent c0c8654 commit b4cca54
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/downloader/config_url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const httpHeadersWikiURLs = {
de: 'https://de.wikipedia.org/wiki/Liste_der_HTTP-Headerfelder',
en: 'https://en.wikipedia.org/wiki/List_of_HTTP_header_fields',
es: 'https://es.wikipedia.org/wiki/Anexo:Cabeceras_HTTP',
pt: 'https://pt.wikipedia.org/wiki/Lista_de_campos_de_cabe%C3%A7alho_HTTP',
'zh-Hans': 'https://zh.wikipedia.org/zh-cn/HTTP%E5%A4%B4%E5%AD%97%E6%AE%B5',
'zh-Hant-HK': 'https://zh.wikipedia.org/zh-hk/HTTP%E5%A4%B4%E5%AD%97%E6%AE%B5',
'zh-Hant-TW': 'https://zh.wikipedia.org/zh-tw/HTTP%E5%A4%B4%E5%AD%97%E6%AE%B5',
Expand Down
36 changes: 34 additions & 2 deletions src/downloader/http_headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ async function main() {
const output = new JsonFileWriter(manifestFiles.httpHeaders("de"));
const html = await getText("de", baseUrl);
const $ = loadHtml(html);
const handleEnglishRow = ($row: Cheerio<Element>, type: ManifestItemType) => {
const handleGermanRow = ($row: Cheerio<Element>, type: ManifestItemType) => {
const $cols = $row.find("td");
if ($cols.length === 0) return;
const headerNames = normalizeHeaderName($cols.eq(0).text());
Expand All @@ -269,7 +269,39 @@ async function main() {
const $rows = element.find("tr");
for (let row = 0; row < $rows.length; row++) {
const $row = $rows.eq(row);
handleEnglishRow($row, ManifestItemType.HttpReqHeader);
handleGermanRow($row, ManifestItemType.HttpReqHeader);
}
}
output.close();
}

// pt
{
const baseUrl = httpHeadersWikiURLs.pt;
const output = new JsonFileWriter(manifestFiles.httpHeaders("pt"));
const html = await getText("pt", baseUrl);
const $ = loadHtml(html);
const handlePortgueseRow = ($row: Cheerio<Element>, type: ManifestItemType) => {
const $cols = $row.find("td");
if ($cols.length === 0) return;
const headerNames = normalizeHeaderName($cols.eq(0).text());
const description = getDescriptionMarkdown($cols.eq(1), baseUrl);
if (!description) print.warn(`header ${headerNames[0]} has no description`);
for (let j = 0; j < headerNames.length; j++) {
const headerName = headerNames[j];
output.writeItem(j === 0 ? [type, headerName, description] : [type, headerName, -1]);
}
};

const $reqH2 = $("h2 #Campos_de_resposta");
assertLength("request fields h2", $reqH2, 1);
const $tables = getNextTables($reqH2.parent(), "h2");
assertLength("request fields table", $tables, 2);
for (const element of $tables) {
const $rows = element.find("tr");
for (let row = 0; row < $rows.length; row++) {
const $row = $rows.eq(row);
handlePortgueseRow($row, ManifestItemType.HttpReqHeader);
}
}
output.close();
Expand Down

0 comments on commit b4cca54

Please sign in to comment.