From ffc1e83af04d58478206d656c54f893d422795d0 Mon Sep 17 00:00:00 2001 From: Eric Arellano Date: Sat, 28 Dec 2024 10:26:24 -0500 Subject: [PATCH] Support multiple policy types in details page --- eleventy.config.ts | 66 ++++++++++---- .../11ty/_includes/policy-record-array.liquid | 10 ++ .../11ty/_includes/policy-record-body.liquid | 24 +++++ scripts/11ty/_includes/style.scss | 14 ++- scripts/11ty/legacy.liquid | 39 ++++++++ scripts/11ty/template.liquid | 47 +++++----- .../abbottstown-pa.html | 75 +++++++++++---- .../abilene-tx.html | 43 +++++---- .../auburn-me.html | 43 +++++---- .../basalt-co.html | 91 +++++++++++++------ 10 files changed, 319 insertions(+), 133 deletions(-) create mode 100644 scripts/11ty/_includes/policy-record-array.liquid create mode 100644 scripts/11ty/_includes/policy-record-body.liquid create mode 100644 scripts/11ty/legacy.liquid diff --git a/eleventy.config.ts b/eleventy.config.ts index d9edabd4..bf297f58 100644 --- a/eleventy.config.ts +++ b/eleventy.config.ts @@ -5,9 +5,28 @@ import CleanCSS from "clean-css"; import { compileString as compileStringSass } from "sass"; import { capitalize } from "lodash-es"; -import { readProcessedCompleteData } from "./scripts/lib/data.js"; +import { + ProcessedCompletePolicy, + readProcessedCompleteData, +} from "./scripts/lib/data.js"; import { escapePlaceId } from "./src/js/data.js"; +function processPolicyRecord(policy: ProcessedCompletePolicy): object { + return { + summary: policy.summary, + date: policy.date?.format(), + status: capitalize(policy.status), + scope: policy.scope.map(capitalize), + landUse: policy.land.map(capitalize), + requirements: policy.requirements.map(capitalize), + reporter: policy.reporter, + citations: policy.citations.map((citation) => ({ + urlDomain: citation.url ? new URL(citation.url).hostname : null, + ...citation, + })), + }; +} + export default async function (eleventyConfig: any) { eleventyConfig.setLiquidOptions({ jsTruthy: true, @@ -23,25 +42,36 @@ export default async function (eleventyConfig: any) { ); const completeData = await readProcessedCompleteData(); - eleventyConfig.addGlobalData( - "entries", - Object.entries(completeData).map(([placeId, entry]) => ({ + const legacy: object[] = []; + const revamp: object[] = []; + Object.entries(completeData).forEach(([placeId, entry]) => { + const common = { placeId, escapedPlaceId: escapePlaceId(placeId), - summary: entry.unifiedPolicy.summary, - date: entry.unifiedPolicy.date?.format(), - status: capitalize(entry.unifiedPolicy.status), - policyChange: entry.unifiedPolicy.policy.map(capitalize), - landUse: entry.unifiedPolicy.land.map(capitalize), - scope: entry.unifiedPolicy.scope.map(capitalize), - requirements: entry.unifiedPolicy.requirements.map(capitalize), - reporter: entry.unifiedPolicy.reporter, - citations: entry.unifiedPolicy.citations.map((citation) => ({ - urlDomain: citation.url ? new URL(citation.url).hostname : null, - ...citation, - })), - })), - ); + population: entry.place.pop.toLocaleString("en-us"), + }; + if ( + entry.add_max?.length || + entry.reduce_min?.length || + entry.rm_min?.length + ) { + revamp.push({ + ...common, + rmMin: entry.rm_min?.map(processPolicyRecord) || [], + reduceMin: entry.reduce_min?.map(processPolicyRecord) || [], + addMax: entry.add_max?.map(processPolicyRecord) || [], + }); + } else { + legacy.push({ + ...common, + ...processPolicyRecord(entry.unifiedPolicy), + policyChange: entry.unifiedPolicy.policy, + }); + } + }); + + eleventyConfig.addGlobalData("legacyEntries", legacy); + eleventyConfig.addGlobalData("entries", revamp); return { dir: { diff --git a/scripts/11ty/_includes/policy-record-array.liquid b/scripts/11ty/_includes/policy-record-array.liquid new file mode 100644 index 00000000..c2c2d2b6 --- /dev/null +++ b/scripts/11ty/_includes/policy-record-array.liquid @@ -0,0 +1,10 @@ +{%- if array.size == 1 -%} + {% render "policy-record-body" record: array[0] %} +{%- else -%} + {%- for item in array -%} +
+

Policy record {{forloop.index}}

+ {% render "policy-record-body" record: item %} +
+ {%- endfor -%} +{%- endif -%} diff --git a/scripts/11ty/_includes/policy-record-body.liquid b/scripts/11ty/_includes/policy-record-body.liquid new file mode 100644 index 00000000..bd8a34fa --- /dev/null +++ b/scripts/11ty/_includes/policy-record-body.liquid @@ -0,0 +1,24 @@ +

{{ record.summary }}

+
+ {% if record.date -%} +
Reform date
+
{{ record.date }}
+ {%- endif %} +
Reform status
+
{{ record.status }}
+
Reform scope
+
{% render "string-array" array: record.scope %}
+
Affected land uses
+
{% render "string-array" array: record.landUse %}
+ {% if record.requirements.size > 0 -%} +
Requirements
+
{% render "string-array" array: record.requirements %}
+ {%- endif %} + {% if record.reporter -%} +
Reporter
+
{{ record.reporter }}
+ {%- endif %} +
+{% for citation in record.citations -%} + {% render "citation" citation: citation numCitations: record.citations.size index: forloop.index %} +{%- endfor %} diff --git a/scripts/11ty/_includes/style.scss b/scripts/11ty/_includes/style.scss index ce31c9d0..4058f12e 100644 --- a/scripts/11ty/_includes/style.scss +++ b/scripts/11ty/_includes/style.scss @@ -230,18 +230,22 @@ $logo-height: 75px; } // ------------------------------------------------------------------------- -// Summary +// Place details // ------------------------------------------------------------------------- -.summary { - font-size: $font-size-md; - margin-bottom: $spacing-container-edge-spacing; +.place-details { + margin-top: $spacing-container-edge-spacing; } // ------------------------------------------------------------------------- -// Metadata list +// Policy record // ------------------------------------------------------------------------- +.summary { + font-size: $font-size-md; + margin-bottom: $spacing-container-edge-spacing; +} + dl { display: grid; grid-template-columns: 1fr; diff --git a/scripts/11ty/legacy.liquid b/scripts/11ty/legacy.liquid new file mode 100644 index 00000000..b74ab7cf --- /dev/null +++ b/scripts/11ty/legacy.liquid @@ -0,0 +1,39 @@ +--- +pagination: + data: legacyEntries + size: 1 + alias: entry +permalink: "{{ entry.escapedPlaceId }}.html" +layout: layout.liquid +--- +
+
+

Parking reforms in {{ entry.placeId }}

+
+

{{ entry.summary }}

+
+
Reform type
+
{% render "string-array" array: entry.policyChange %}
+ {% if entry.date -%} +
Reform date
+
{{ entry.date }}
+ {%- endif %} +
Reform status
+
{{ entry.status }}
+
Reform scope
+
{% render "string-array" array: entry.scope %}
+
Affected land uses
+
{% render "string-array" array: entry.landUse %}
+ {% if entry.requirements.size > 0 -%} +
Requirements
+
{% render "string-array" array: entry.requirements %}
+ {%- endif %} + {% if entry.reporter -%} +
Reporter
+
{{ entry.reporter }}
+ {%- endif %} +
+ {% for citation in entry.citations -%} + {% render "citation" citation: citation numCitations: entry.citations.size index: forloop.index %} + {%- endfor %} +
diff --git a/scripts/11ty/template.liquid b/scripts/11ty/template.liquid index 2e0d9fb6..d35cc302 100644 --- a/scripts/11ty/template.liquid +++ b/scripts/11ty/template.liquid @@ -10,30 +10,25 @@ layout: layout.liquid

Parking reforms in {{ entry.placeId }}

-

{{ entry.summary }}

-
-
Reform type
-
{% render "string-array" array: entry.policyChange %}
- {% if entry.date -%} -
Reform date
-
{{ entry.date }}
- {%- endif %} -
Reform status
-
{{ entry.status }}
-
Reform scope
-
{% render "string-array" array: entry.scope %}
-
Affected land uses
-
{% render "string-array" array: entry.landUse %}
- {% if entry.requirements.size > 0 -%} -
Requirements
-
{% render "string-array" array: entry.requirements %}
- {%- endif %} - {% if entry.reporter -%} -
Reporter
-
{{ entry.reporter }}
- {%- endif %} -
- {% for citation in entry.citations -%} - {% render "citation" citation: citation numCitations: entry.citations.size index: forloop.index %} - {%- endfor %} + + {% if entry.rmMin.size > 0 -%} +
+

Parking minimum removal{% if entry.rmMin.size > 1 %}s{% endif %}

+ {% render "policy-record-array" array: entry.rmMin %} +
+ {%- endif %} + {% if entry.reduceMin.size > 0 -%} +
+

Parking minimum reduction{% if entry.addMax.size > 1 %}s{% endif %}

+ {% render "policy-record-array" array: entry.reduceMin %} +
+ {%- endif %} + {% if entry.addMax.size > 0 -%} +
+

Parking maximum{% if entry.addMax.size > 1 %}s{% endif %}

+ {% render "policy-record-array" array: entry.addMax %} +
+ {%- endif %} diff --git a/tests/scripts/generateHtmlPages.test.ts-snapshots/abbottstown-pa.html b/tests/scripts/generateHtmlPages.test.ts-snapshots/abbottstown-pa.html index 3270c75e..8b8ed63c 100644 --- a/tests/scripts/generateHtmlPages.test.ts-snapshots/abbottstown-pa.html +++ b/tests/scripts/generateHtmlPages.test.ts-snapshots/abbottstown-pa.html @@ -3,7 +3,7 @@ - + Parking reforms in Abbottstown, PA | Parking Reform Network