Skip to content

Commit

Permalink
Downloads: do not include full account URLs
Browse files Browse the repository at this point in the history
Fixes govdirectory#488.

Side effect: remove accounts from country level downloads.
  • Loading branch information
Abbe98 committed Jan 10, 2025
1 parent 58d11cb commit 3369084
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
13 changes: 4 additions & 9 deletions templates/country-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,26 +82,21 @@ <h2 class="m0 expand-mobile">Agencies</h2>
<script>
const dataTable = document.querySelector('table');

let tsv = '"Name"\t"Govdirectory URL"\t"Type"\t"Website"\t"Accounts"\n';
let tsv = '"Name"\t"Govdirectory URL"\t"Type"\t"Website"\n';
Array.from(dataTable.children[1].children).forEach((row, index) => {
const name = row.children[0].innerText;
const qid = row.children[0].firstChild.href;
const type = row.children[2].innerText;
var website = '';
var accounts = '';
if (row.children[1].firstChild) {
accounts = Array.from(row.children[1].firstChild.children).map(item => {
Array.from(row.children[1].firstChild.children).map(item => {
if (item.firstChild.title === 'Website') {
website = item.firstChild.href;
return;
}
return item.firstChild.href;
}).join('|');
accounts = accounts.replace('||', '|');
// remove trailing and leading pipes
accounts = accounts.replace(/^\|+|\|+$/g, '');
});
}
const tsvRow = '"' + name + '"\t"' + qid + '"\t"' + type + '"\t"' + website + '"\t"' + accounts + '"\n';
const tsvRow = '"' + name + '"\t"' + qid + '"\t"' + type + '"\t"' + website + '"\n"';
tsv += tsvRow;
});

Expand Down
4 changes: 2 additions & 2 deletions templates/org.html
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,15 @@ <h2 class="m0">Platforms and accounts</h2>
const dataTable = document.querySelector('table.container');

if (dataTable) {
let tsv = '"Platform","Account link",\n';
let tsv = '"Platform","Account",\n';
Array.from(dataTable.children[0].children).forEach((row, index) => {
if (index === 0) return; // header
const columns = Array.from(row.children);
let rowTSV = '';
columns.forEach((column, innerIndex) => {
let value;
if (column.children[0] && column.children[0].nodeName === 'A') {
value = column.children[0].href;
value = column.children[0].href.split("/").pop();
} else {
value = column.innerText;
}
Expand Down
2 changes: 1 addition & 1 deletion templates/topic-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ <h2 class="m0 expand-mobile">Agencies</h2>
var accounts;
if (row.children[1].firstChild) {
accounts = Array.from(row.children[1].firstChild.children).map(item => {
return item.firstChild.href;
return item.firstChild.href.split('/').pop();
}).join('|');
} else {
accounts = '';
Expand Down

0 comments on commit 3369084

Please sign in to comment.