added county page generation
This commit is contained in:
parent
6184b31fda
commit
46a3a4f528
25
generate.js
25
generate.js
@ -690,9 +690,11 @@ const processRecords = async () => {
|
||||
|
||||
const singleCountryTmpl = path.join(templatesDir, 'country.pug');
|
||||
const singleStateTmpl = path.join(templatesDir, 'state.pug');
|
||||
const singleCountyTmpl = path.join(templatesDir, 'county.pug');
|
||||
|
||||
const countryFn = pug.compileFile(singleCountryTmpl);
|
||||
const stateFn = pug.compileFile(singleStateTmpl);
|
||||
const countyFn = pug.compileFile(singleCountyTmpl);
|
||||
|
||||
await Promise.all(countryArr.map(async (countryData) => {
|
||||
const start = Date.now();
|
||||
@ -721,6 +723,29 @@ const processRecords = async () => {
|
||||
await promiseMe(callback => fs.writeFile(targetFile, stateHtml, callback));
|
||||
console.log(`wrote to ${targetFile} in ${Date.now() - start}ms`);
|
||||
}));
|
||||
|
||||
for (const stateData of countryData.states) {
|
||||
if (!stateData.name || !stateData.counties || !stateData.counties.length) {
|
||||
continue;
|
||||
}
|
||||
await Promise.all(stateData.counties.map(async (countyData) => {
|
||||
countyData.population = countyData.population || 0;
|
||||
|
||||
const start = Date.now();
|
||||
const targetFile = path.join(
|
||||
publicDir,
|
||||
'countries',
|
||||
`${countryData.safeName}-${stateData.safeName}-${countyData.safeName}.html`,
|
||||
);
|
||||
const countyHtml = countyFn({
|
||||
data: countyData,
|
||||
$title: `${countyData.name}, ${countyData.state}, ${countyData.country}`,
|
||||
lastUpdate,
|
||||
});
|
||||
await promiseMe(callback => fs.writeFile(targetFile, countyHtml, callback));
|
||||
console.log(`wrote to ${targetFile} in ${Date.now() - start}ms`);
|
||||
}));
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
|
14
tmpl/county.pug
Normal file
14
tmpl/county.pug
Normal file
@ -0,0 +1,14 @@
|
||||
extends ./master.pug
|
||||
|
||||
block main
|
||||
h2.d-flex.justify-content-between
|
||||
span= data.name + ', ' + data.state
|
||||
a.align-self-center(href=("/countries/" + data.countrySafeName + "-" + data.stateSafeName + ".html") style="font-size: 50%")
|
||||
| ◀ #{data.state}
|
||||
|
||||
+heroChart
|
||||
|
||||
mixin renderItemName(item)
|
||||
= item.name
|
||||
|
||||
+dataTable([ data ], 'County', 'county')
|
@ -458,8 +458,15 @@ html
|
||||
const casesPerMillion = Math.round(data.casesPerMillion).toLocaleString() + '/1M';
|
||||
const totalDeaths = data.total.toLocaleString();
|
||||
const totalCases = data.cases.total.toLocaleString();
|
||||
let name = data.name;
|
||||
if (data.county) {
|
||||
name += ', ' + data.state;
|
||||
}
|
||||
if (data.country) {
|
||||
name += ', ' + data.country;
|
||||
}
|
||||
const heroTitle = [
|
||||
`Covid-19: ${data.name} (${population})`,
|
||||
`Covid-19: ${name} (${population})`,
|
||||
`${totalCases} cases (${casesPerMillion})`,
|
||||
`${totalDeaths} deaths (${deathsPerMillion})`,
|
||||
];
|
||||
|
@ -9,7 +9,10 @@ block main
|
||||
+heroChart
|
||||
|
||||
mixin renderItemName(item)
|
||||
if item.name
|
||||
if item.name && item.country === 'United States'
|
||||
a(href=("/countries/" + data.countrySafeName + "-" + data.safeName + "-" + item.safeName + ".html"))
|
||||
= item.name
|
||||
else if item.name
|
||||
= item.name
|
||||
else
|
||||
em.text-muted Other #{item.state}
|
||||
|
Loading…
Reference in New Issue
Block a user