From be13db2d91f592f48eb8543c07050b2c6ddb88a6 Mon Sep 17 00:00:00 2001 From: Daniel Wood Date: Wed, 20 Jul 2022 12:07:53 -0400 Subject: [PATCH 01/18] add template name to manifest.json --- lib/createGraphic.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/createGraphic.js b/lib/createGraphic.js index 0777507..be5c670 100644 --- a/lib/createGraphic.js +++ b/lib/createGraphic.js @@ -54,6 +54,11 @@ module.exports = async function(config, template, slug, sheetID) { console.log(`Using existing sheet ${sheetID}`); } + // add template info to manifest + if (template) { + manifest.templateType = template; + } + try { // snapshot the current global packages for the record, in case we upgrade later var package = await readJSON(path.join(config.root, "package.json")); From 08a1d1d17edaddef7d1d006fb818b94378b0bc6d Mon Sep 17 00:00:00 2001 From: Daniel Wood Date: Wed, 20 Jul 2022 13:10:14 -0400 Subject: [PATCH 02/18] add parent info to manifest.json --- lib/duplicateGraphic.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/duplicateGraphic.js b/lib/duplicateGraphic.js index f9b508d..ac56e1e 100644 --- a/lib/duplicateGraphic.js +++ b/lib/duplicateGraphic.js @@ -29,7 +29,7 @@ module.exports = async function(config, original, slug) { console.log("Loading manifest"); var manifestPath = path.join(dest, "manifest.json"); var manifest = await readJSON(manifestPath); - var { sheet } = manifest; + var { sheet,parent } = manifest; if (sheet) { console.log("Duplicating existing sheet"); @@ -42,6 +42,17 @@ module.exports = async function(config, original, slug) { } } + //load/create parent info + if (parent) { + console.log(parent) + manifest.parent.push(original) + } else { + manifest.parent = [original] + } + // console.log(config) + console.log(original) + // console.log(slug) + await fs.writeFile(manifestPath, JSON.stringify(manifest, null, 2)); console.log(`Duplicate of ${original} created as ${fullSlug} -- you got this!`); From 54723d0cd50ba3a9c83388a8801630136690a066 Mon Sep 17 00:00:00 2001 From: Daniel Wood Date: Wed, 20 Jul 2022 13:38:04 -0400 Subject: [PATCH 03/18] pass metadata forward from the root --- server/handlers/root.js | 30 +++++++++++++++++++++++++++++- server/templates/rootList.html | 4 +++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/server/handlers/root.js b/server/handlers/root.js index 5a6ba42..77a58b6 100644 --- a/server/handlers/root.js +++ b/server/handlers/root.js @@ -1,5 +1,6 @@ var fs = require("fs").promises; var path = require("path"); +var readJSON = require("../../lib/readJSON"); var getFolders = async function(dir) { var listing = await fs.readdir(dir); @@ -18,6 +19,31 @@ var getFolders = async function(dir) { return matching; }; +var getMetadata = async function(data,dir) { + var metadata = {}; + for (var i = 0; i < data.length; i++) { + var manifest = await readJSON(path.join(dir, data[i], "manifest.json")); + if (manifest.templateType) { + var template = manifest.templateType; + } else { + var template = ""; + } + + if (manifest.parent) { + var parent = manifest.parent; + } else { + var parent = ""; + } + + metadata[data[i]] = { + "templateType":template, + "parent":parent + } + } + return metadata; +}; + + module.exports = async function(request, response) { var app = request.app; var config = app.get("config"); @@ -25,5 +51,7 @@ module.exports = async function(request, response) { var graphics = await getFolders(config.root); var templates = await getFolders(config.templateRoot); - response.render("rootList.html", { graphics, templates }); + var graphicMetadata = await getMetadata(graphics,config.root) + + response.render("rootList.html", { graphics, templates, graphicMetadata }); }; diff --git a/server/templates/rootList.html b/server/templates/rootList.html index fd0f8d9..c4a511f 100644 --- a/server/templates/rootList.html +++ b/server/templates/rootList.html @@ -29,7 +29,9 @@

daily.graphics

    - <% graphics.forEach(function(g) { %> + <% graphics.forEach(function(g) { + console.log(graphicMetadata[g].templateType) + %>
  1. <%= g %> From 408ab1a57d92308a4b3af191d897bd61fc3093b7 Mon Sep 17 00:00:00 2001 From: Daniel Wood Date: Wed, 20 Jul 2022 14:47:56 -0400 Subject: [PATCH 04/18] table view for rootList.html --- server/handlers/root.js | 2 +- server/static/style.css | 33 +++++++++++++++++++- server/templates/rootList.html | 56 +++++++++++++++++++++++++++------- 3 files changed, 78 insertions(+), 13 deletions(-) diff --git a/server/handlers/root.js b/server/handlers/root.js index 77a58b6..732663c 100644 --- a/server/handlers/root.js +++ b/server/handlers/root.js @@ -32,7 +32,7 @@ var getMetadata = async function(data,dir) { if (manifest.parent) { var parent = manifest.parent; } else { - var parent = ""; + var parent = []; } metadata[data[i]] = { diff --git a/server/static/style.css b/server/static/style.css index 89b87bd..20d449b 100644 --- a/server/static/style.css +++ b/server/static/style.css @@ -258,7 +258,7 @@ select { } .root-list .graphics-list { - max-width: 400px; + /*max-width: 600px;*/ margin: 40px auto; } @@ -283,6 +283,37 @@ select { display: none; } + +/* Table view home page */ + + +/*// Base table styles*/ +div.graphics-list { + max-width: 1000px; +} + +table { + border-collapse: collapse; + padding: 0; + width: 100%; + color: #666; +} + +table th { + line-height: 1.2; + text-align: left; + vertical-align: bottom; +} + +table td { + vertical-align: top; + margin: 2px 0; + padding: 2px; + font-size: 18px; + border-bottom: 1px dashed var(--light-gray); + height: 20px; +} + /* preview page */ .preview-page a.back { diff --git a/server/templates/rootList.html b/server/templates/rootList.html index c4a511f..0d31c54 100644 --- a/server/templates/rootList.html +++ b/server/templates/rootList.html @@ -27,18 +27,52 @@

    daily.graphics

    - -
      - <% graphics.forEach(function(g) { - console.log(graphicMetadata[g].templateType) - %> -
    1. -
      - <%= g %> -
      - <% }); %> -
    +
    + + + + + + + + + + + <% graphics.forEach(function(g) { + var date = g.split("-") + var date = date[date.length -1] + var date = `${date.substring(4, 6)}/${date.substring(6, 8)}/${date.substring(0, 4)}` + var olds = ["🧓🏻","👴🏻","👵🏻","🧓🏼","👴🏼","👵🏼","🧓🏽","👴🏽","👵🏽","🧓🏾","👴🏾","👵🏾","🧓🏿","👴🏿","👵🏿"] + var randOld = olds[Math.floor(Math.random()*15)]; + var lineage = graphicMetadata[g].parent.join(`
    ${randOld} `) + %> + + + + + + + <% }); %> + +
    +
    +
    Slug
    +
    +
    +
    Creation Date
    +
    +
    +
    Original template
    +
    +
    +
    Lineage
    +
    +
    + <%= g %> +
    +
    <%= date%><%= graphicMetadata[g].templateType %><%= lineage %>
    +
    \ No newline at end of file From 9b0bfaf24b8ce4a3fb7ca52e0e64c23561e41b27 Mon Sep 17 00:00:00 2001 From: Daniel Wood Date: Wed, 20 Jul 2022 15:09:47 -0400 Subject: [PATCH 05/18] add template info to each manifest.json --- lib/duplicateGraphic.js | 4 ---- server/handlers/root.js | 35 ++++++++++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/lib/duplicateGraphic.js b/lib/duplicateGraphic.js index ac56e1e..c55dcf8 100644 --- a/lib/duplicateGraphic.js +++ b/lib/duplicateGraphic.js @@ -44,14 +44,10 @@ module.exports = async function(config, original, slug) { //load/create parent info if (parent) { - console.log(parent) manifest.parent.push(original) } else { manifest.parent = [original] } - // console.log(config) - console.log(original) - // console.log(slug) await fs.writeFile(manifestPath, JSON.stringify(manifest, null, 2)); console.log(`Duplicate of ${original} created as ${fullSlug} -- you got this!`); diff --git a/server/handlers/root.js b/server/handlers/root.js index 732663c..ec0a0fb 100644 --- a/server/handlers/root.js +++ b/server/handlers/root.js @@ -2,6 +2,27 @@ var fs = require("fs").promises; var path = require("path"); var readJSON = require("../../lib/readJSON"); +var templateList = { + "1G5p4UIsKwUK303k4gLXhAmFnret0lg3w7qLm5S62Tsg":"ai2html_graphic", + "1nbpweBccoaBqxuyKSL6o0q_qkdponL0OWgJpbozQp58":"bar_chart", + "1km6lszUzHwbgg9eFe1qcsUHfQBIF48r1XnFc1nQcnog":"county_map", + "12PsbQ7uTHr_iFeJLgt7LSkU66BQUNX8_5wQrJuvjYFU":"stacked_grouped_column_chart", + "12e3cNKWd1E2IHcDGN72URkbp7Yjb_3TbJrAxIgpYCTI":"state_grid_map", + "1E0fEV2lnchh8l5fuTvOTR5GRuv4jVtOEI-unEOCPtd4":"portrait_pullquotes", + "1kekyEB3w293-8Ex2R3VdsQZTQmrfJwZ6sfWxS7OBDyA":"graphic", + "1pcLyLFhEpKMlNpp3UqWZ1XgW8ZaloVe_d04CGdNnEWc":"dot_chart", + "1a8F0oYWVC0BdEpG8Mbz2HKRkGIn0XQiGWTcVZMXeVdQ":"table", + "1kekyEB3w293-8Ex2R3VdsQZTQmrfJwZ6sfWxS7OBDyA":"d3_graphic", + "1wq0oi5HfgfYBdDs32-Qs77xmnI9VMXPUgRHA8lKIRmM":"annotated_line_chart", + "1QTLmFGjd2BCU3QQvvXb-8RN9YkztBFOaOeaZ40SEKjw":"block_histogram", + "1-wN8QJAaAE5zzIMcbfPPchPWAGFj6BnpZrU72Fp6cm4":"column_chart", + "1G5p4UIsKwUK303k4gLXhAmFnret0lg3w7qLm5S62Tsg":"ai2html_map", + "1DLHWPcJcGoKHRGBtATdBbZVIT0EuiAXG_SiQiDucazg":"stacked_bar_chart", + "1DLxMcQRpyp1rqGJTjC28jJH5Df1GYrJrJnBl2PW9-MU":"line_chart", + "19d-SxZs0z5fl7pETB427wp4DYzNwB5znkNZg6kF69j4":"grouped_bar_chart", + "1tCkiSX2QV2_LjXWW6sNe7s9MqREeDEYrIGQF8mb0OHw":"stacked_column_chart" +} + var getFolders = async function(dir) { var listing = await fs.readdir(dir); var matching = []; @@ -22,11 +43,19 @@ var getFolders = async function(dir) { var getMetadata = async function(data,dir) { var metadata = {}; for (var i = 0; i < data.length; i++) { - var manifest = await readJSON(path.join(dir, data[i], "manifest.json")); - if (manifest.templateType) { + var manifestPath = path.join(dir, data[i], "manifest.json"); + var manifest = await readJSON(manifestPath); + if (manifest.templateType && manifest.templateType != "test") { var template = manifest.templateType; + } + else if (manifest.templateType == "test") { + var template = templateList[manifest.templateSheet]; + + manifest.templateType = template; + // update manifest with test + await fs.writeFile(manifestPath, JSON.stringify(manifest, null, 2)); } else { - var template = ""; + template = ""; } if (manifest.parent) { From b3131cf4afb3d418174d1f923ff8703476ffc1b0 Mon Sep 17 00:00:00 2001 From: Daniel Wood Date: Wed, 20 Jul 2022 15:49:44 -0400 Subject: [PATCH 06/18] clean up --- server/handlers/root.js | 28 ---------------------------- server/templates/rootList.html | 6 ++---- 2 files changed, 2 insertions(+), 32 deletions(-) diff --git a/server/handlers/root.js b/server/handlers/root.js index ec0a0fb..6129694 100644 --- a/server/handlers/root.js +++ b/server/handlers/root.js @@ -2,27 +2,6 @@ var fs = require("fs").promises; var path = require("path"); var readJSON = require("../../lib/readJSON"); -var templateList = { - "1G5p4UIsKwUK303k4gLXhAmFnret0lg3w7qLm5S62Tsg":"ai2html_graphic", - "1nbpweBccoaBqxuyKSL6o0q_qkdponL0OWgJpbozQp58":"bar_chart", - "1km6lszUzHwbgg9eFe1qcsUHfQBIF48r1XnFc1nQcnog":"county_map", - "12PsbQ7uTHr_iFeJLgt7LSkU66BQUNX8_5wQrJuvjYFU":"stacked_grouped_column_chart", - "12e3cNKWd1E2IHcDGN72URkbp7Yjb_3TbJrAxIgpYCTI":"state_grid_map", - "1E0fEV2lnchh8l5fuTvOTR5GRuv4jVtOEI-unEOCPtd4":"portrait_pullquotes", - "1kekyEB3w293-8Ex2R3VdsQZTQmrfJwZ6sfWxS7OBDyA":"graphic", - "1pcLyLFhEpKMlNpp3UqWZ1XgW8ZaloVe_d04CGdNnEWc":"dot_chart", - "1a8F0oYWVC0BdEpG8Mbz2HKRkGIn0XQiGWTcVZMXeVdQ":"table", - "1kekyEB3w293-8Ex2R3VdsQZTQmrfJwZ6sfWxS7OBDyA":"d3_graphic", - "1wq0oi5HfgfYBdDs32-Qs77xmnI9VMXPUgRHA8lKIRmM":"annotated_line_chart", - "1QTLmFGjd2BCU3QQvvXb-8RN9YkztBFOaOeaZ40SEKjw":"block_histogram", - "1-wN8QJAaAE5zzIMcbfPPchPWAGFj6BnpZrU72Fp6cm4":"column_chart", - "1G5p4UIsKwUK303k4gLXhAmFnret0lg3w7qLm5S62Tsg":"ai2html_map", - "1DLHWPcJcGoKHRGBtATdBbZVIT0EuiAXG_SiQiDucazg":"stacked_bar_chart", - "1DLxMcQRpyp1rqGJTjC28jJH5Df1GYrJrJnBl2PW9-MU":"line_chart", - "19d-SxZs0z5fl7pETB427wp4DYzNwB5znkNZg6kF69j4":"grouped_bar_chart", - "1tCkiSX2QV2_LjXWW6sNe7s9MqREeDEYrIGQF8mb0OHw":"stacked_column_chart" -} - var getFolders = async function(dir) { var listing = await fs.readdir(dir); var matching = []; @@ -47,13 +26,6 @@ var getMetadata = async function(data,dir) { var manifest = await readJSON(manifestPath); if (manifest.templateType && manifest.templateType != "test") { var template = manifest.templateType; - } - else if (manifest.templateType == "test") { - var template = templateList[manifest.templateSheet]; - - manifest.templateType = template; - // update manifest with test - await fs.writeFile(manifestPath, JSON.stringify(manifest, null, 2)); } else { template = ""; } diff --git a/server/templates/rootList.html b/server/templates/rootList.html index 0d31c54..ef1536c 100644 --- a/server/templates/rootList.html +++ b/server/templates/rootList.html @@ -54,10 +54,8 @@

    daily.graphics

    <% graphics.forEach(function(g) { var date = g.split("-") var date = date[date.length -1] - var date = `${date.substring(4, 6)}/${date.substring(6, 8)}/${date.substring(0, 4)}` - var olds = ["🧓🏻","👴🏻","👵🏻","🧓🏼","👴🏼","👵🏼","🧓🏽","👴🏽","👵🏽","🧓🏾","👴🏾","👵🏾","🧓🏿","👴🏿","👵🏿"] - var randOld = olds[Math.floor(Math.random()*15)]; - var lineage = graphicMetadata[g].parent.join(`
    ${randOld} `) + var date = `${date.substring(4, 6)}/${date.substring(6, 8)}/${date.substring(0, 4)}` + var lineage = graphicMetadata[g].parent.join(`
    👉`) %> From 7707e04efdbc7de49df0f3ab2ee933c2e84aa052 Mon Sep 17 00:00:00 2001 From: Daniel Wood Date: Thu, 21 Jul 2022 08:38:27 -0400 Subject: [PATCH 07/18] connect search for slugs --- server/static/rootPage.js | 8 +++++--- server/static/style.css | 4 ++++ server/templates/rootList.html | 20 ++++++++++---------- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/server/static/rootPage.js b/server/static/rootPage.js index 04b8173..1c5d582 100644 --- a/server/static/rootPage.js +++ b/server/static/rootPage.js @@ -7,9 +7,11 @@ var graphicItems = $(".graphics-list .item"); var filterGraphics = function() { var value = searchInput.value; var re = new RegExp(value); - graphicItems.forEach(li => { - var { slug } = li.dataset; - li.classList.toggle("hide", !slug.match(re)); + console.log(re) + + graphicItems.forEach(tr => { + var { slug } = tr.dataset; + tr.classList.toggle("hide", !slug.match(re)); }); }; diff --git a/server/static/style.css b/server/static/style.css index 20d449b..27ac538 100644 --- a/server/static/style.css +++ b/server/static/style.css @@ -314,6 +314,10 @@ table td { height: 20px; } +table tr.hide { + display: none; +} + /* preview page */ .preview-page a.back { diff --git a/server/templates/rootList.html b/server/templates/rootList.html index ef1536c..4662f65 100644 --- a/server/templates/rootList.html +++ b/server/templates/rootList.html @@ -57,16 +57,16 @@

    daily.graphics

    var date = `${date.substring(4, 6)}/${date.substring(6, 8)}/${date.substring(0, 4)}` var lineage = graphicMetadata[g].parent.join(`
    👉`) %> - - -
    - <%= g %> -
    - - <%= date%> - <%= graphicMetadata[g].templateType %> - <%= lineage %> - + + +
    + <%= g %> +
    + + <%= date%> + <%= graphicMetadata[g].templateType %> + <%= lineage %> + <% }); %> From fd248e3d5bf4e7a26af9b3c5741c1ce6b29fa793 Mon Sep 17 00:00:00 2001 From: Daniel Wood Date: Thu, 21 Jul 2022 08:58:47 -0400 Subject: [PATCH 08/18] add filter for templates --- server/static/rootPage.js | 22 +++++++++++++--------- server/static/style.css | 3 ++- server/templates/rootList.html | 17 +++++++++-------- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/server/static/rootPage.js b/server/static/rootPage.js index 1c5d582..cd096d6 100644 --- a/server/static/rootPage.js +++ b/server/static/rootPage.js @@ -1,22 +1,26 @@ import { showToast } from "./toast.js"; import { $ } from "./qsa.js"; -var searchInput = $.one(".search-graphics"); +var slugInput = $.one(".search-graphics"); +var templateInput = $.one(".search-templates"); + var graphicItems = $(".graphics-list .item"); -var filterGraphics = function() { - var value = searchInput.value; +var filterGraphics = function(inputBox,items,key) { + var value = inputBox.value; var re = new RegExp(value); - console.log(re) - graphicItems.forEach(tr => { - var { slug } = tr.dataset; - tr.classList.toggle("hide", !slug.match(re)); + items.forEach(tr => { + var thing = tr.dataset[key]; + tr.classList.toggle("hide", !thing.match(re)); }); }; -searchInput.addEventListener("keyup", filterGraphics); -filterGraphics(); +slugInput.addEventListener("keyup", () => filterGraphics(slugInput,graphicItems,"slug")); +filterGraphics(slugInput,graphicItems,"slug"); + +templateInput.addEventListener("keyup", () => filterGraphics(templateInput,graphicItems,"template")); +filterGraphics(templateInput,graphicItems,"template"); var createShade = $.one(".create.shade"); var toggleCreate = $.one(".new-graphic"); diff --git a/server/static/style.css b/server/static/style.css index 27ac538..35ad559 100644 --- a/server/static/style.css +++ b/server/static/style.css @@ -173,6 +173,7 @@ select { border: 0; background: var(--off-white); padding: 0 10px; + margin: 0 5px; } .toolbar .spacer { @@ -289,7 +290,7 @@ select { /*// Base table styles*/ div.graphics-list { - max-width: 1000px; + max-width: 600px; } table { diff --git a/server/templates/rootList.html b/server/templates/rootList.html index 4662f65..d6ae17b 100644 --- a/server/templates/rootList.html +++ b/server/templates/rootList.html @@ -11,7 +11,8 @@

    daily.graphics

    - + +
    @@ -36,18 +37,18 @@

    daily.graphics

    Slug
    - +
    Original template
    - + @@ -57,15 +58,15 @@

    daily.graphics

    var date = `${date.substring(4, 6)}/${date.substring(6, 8)}/${date.substring(0, 4)}` var lineage = graphicMetadata[g].parent.join(`
    👉`) %> - + - <%= date%> + <%= graphicMetadata[g].templateType %> - <%= lineage %> + <% }); %> From 0405521352428d0a1a289df4535d0ae5991e7f9f Mon Sep 17 00:00:00 2001 From: Daniel Wood Date: Thu, 21 Jul 2022 10:17:53 -0400 Subject: [PATCH 09/18] add lineage to ui --- server/static/style.css | 2 +- server/templates/rootList.html | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/server/static/style.css b/server/static/style.css index 35ad559..de44bfe 100644 --- a/server/static/style.css +++ b/server/static/style.css @@ -290,7 +290,7 @@ select { /*// Base table styles*/ div.graphics-list { - max-width: 600px; + max-width: 1000px; } table { diff --git a/server/templates/rootList.html b/server/templates/rootList.html index d6ae17b..7d76668 100644 --- a/server/templates/rootList.html +++ b/server/templates/rootList.html @@ -37,18 +37,18 @@

    daily.graphics

    Slug
    - +
    Original template
    - + @@ -64,9 +64,9 @@

    daily.graphics

    <%= g %>
    - + <%= date%> <%= graphicMetadata[g].templateType %> - + <%= lineage %> <% }); %> From 827142a031879d9c346b218011c034c3d9c9761b Mon Sep 17 00:00:00 2001 From: Daniel Wood Date: Thu, 21 Jul 2022 10:21:11 -0400 Subject: [PATCH 10/18] further cleanup --- server/handlers/root.js | 2 +- server/templates/rootList.html | 9 +-------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/server/handlers/root.js b/server/handlers/root.js index 6129694..dc20886 100644 --- a/server/handlers/root.js +++ b/server/handlers/root.js @@ -24,7 +24,7 @@ var getMetadata = async function(data,dir) { for (var i = 0; i < data.length; i++) { var manifestPath = path.join(dir, data[i], "manifest.json"); var manifest = await readJSON(manifestPath); - if (manifest.templateType && manifest.templateType != "test") { + if (manifest.templateType) { var template = manifest.templateType; } else { template = ""; diff --git a/server/templates/rootList.html b/server/templates/rootList.html index d6ae17b..847fd5c 100644 --- a/server/templates/rootList.html +++ b/server/templates/rootList.html @@ -52,21 +52,14 @@

    daily.graphics

    - <% graphics.forEach(function(g) { - var date = g.split("-") - var date = date[date.length -1] - var date = `${date.substring(4, 6)}/${date.substring(6, 8)}/${date.substring(0, 4)}` - var lineage = graphicMetadata[g].parent.join(`
    👉`) - %> + <% graphics.forEach(function(g) {%> - <%= graphicMetadata[g].templateType %> - <% }); %> From f192718f9acc2fe497f51db4a6b23e86f410a9c8 Mon Sep 17 00:00:00 2001 From: Daniel Wood Date: Thu, 21 Jul 2022 10:25:34 -0400 Subject: [PATCH 11/18] one more cleanup --- server/templates/rootList.html | 8 -------- 1 file changed, 8 deletions(-) diff --git a/server/templates/rootList.html b/server/templates/rootList.html index 847fd5c..6440313 100644 --- a/server/templates/rootList.html +++ b/server/templates/rootList.html @@ -37,18 +37,10 @@

    daily.graphics

    Slug
    -
    Original template
    - From 169d7631938dd1b056d3b06e7630028b591b9716 Mon Sep 17 00:00:00 2001 From: Daniel Wood Date: Thu, 28 Jul 2022 13:12:23 -0400 Subject: [PATCH 12/18] parse template list in rootList.html --- server/templates/rootList.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/templates/rootList.html b/server/templates/rootList.html index 6440313..a352430 100644 --- a/server/templates/rootList.html +++ b/server/templates/rootList.html @@ -51,7 +51,7 @@

    daily.graphics

    <%= g %> - <%= graphicMetadata[g].templateType %> + <%= graphicMetadata[g].templateType.replace(/(_|^)(\w)/g, (_, p, s) => " " + s.toUpperCase()) %> <% }); %> From 5f02e5c56a1854d82bd768400f33857531a22533 Mon Sep 17 00:00:00 2001 From: Daniel Wood Date: Fri, 19 Aug 2022 11:26:59 -0400 Subject: [PATCH 13/18] fix parsing of template search to replace space with underscore --- server/static/rootPage.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server/static/rootPage.js b/server/static/rootPage.js index cd096d6..5bf93a5 100644 --- a/server/static/rootPage.js +++ b/server/static/rootPage.js @@ -8,6 +8,11 @@ var graphicItems = $(".graphics-list .item"); var filterGraphics = function(inputBox,items,key) { var value = inputBox.value; + + if (key == "template") { + value = value.replaceAll(" ","_") + } + var re = new RegExp(value); items.forEach(tr => { From 1429419650ac2667e9d993b607068761b989c45e Mon Sep 17 00:00:00 2001 From: Daniel Wood Date: Wed, 25 Oct 2023 10:34:07 -0400 Subject: [PATCH 14/18] idk what happened to the lineage working --- server/templates/rootList.html | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/server/templates/rootList.html b/server/templates/rootList.html index a8ad6b9..1034771 100644 --- a/server/templates/rootList.html +++ b/server/templates/rootList.html @@ -53,16 +53,19 @@

    daily.graphics

    - <% graphics.forEach(function(g) {%> + <% graphics.forEach(function(g) { + console.log(graphicMetadata[g]) + + %> - <%= date%> + <%= graphicMetadata[g].templateType.replace(/(_|^)(\w)/g, (_, p, s) => " " + s.toUpperCase()) %> - <%= lineage %> + <% }); %> From 43a703b38ddb92eb9399636b9a51ea5c1c831fe5 Mon Sep 17 00:00:00 2001 From: Daniel Wood Date: Wed, 25 Oct 2023 11:09:54 -0400 Subject: [PATCH 15/18] make lineage function --- server/templates/rootList.html | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/server/templates/rootList.html b/server/templates/rootList.html index 1034771..371fe62 100644 --- a/server/templates/rootList.html +++ b/server/templates/rootList.html @@ -37,11 +37,10 @@

    daily.graphics

    Slug
    - - +
    Original template
    @@ -54,8 +53,7 @@

    daily.graphics

    <% graphics.forEach(function(g) { - console.log(graphicMetadata[g]) - + let lineage = graphicMetadata[g].parent.join("👉") %> @@ -63,9 +61,8 @@

    daily.graphics

    <%= g %> - <%= graphicMetadata[g].templateType.replace(/(_|^)(\w)/g, (_, p, s) => " " + s.toUpperCase()) %> - + <%= lineage %> <% }); %> From 48cdff9df5d54a526f5722432d60fd14d709771b Mon Sep 17 00:00:00 2001 From: Daniel Wood Date: Thu, 8 Feb 2024 13:32:51 -0500 Subject: [PATCH 16/18] fixes smartypants bug; closes #64 (#67) Co-authored-by: Brent Jones --- lib/templateFilters.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/templateFilters.js b/lib/templateFilters.js index 901cafc..3478f80 100644 --- a/lib/templateFilters.js +++ b/lib/templateFilters.js @@ -104,7 +104,8 @@ var smarty = function(text) { var typos = [typogr.amp, typogr.smartypants, typogr.widont, typogr.ord]; var output = typos.reduce((v, f) => f(v), text); output = output.replace(/–/g, "—") - .replace(/([’']) ([”"])/g, "$1 $2"); + .replace(/([’']) ([”"])/g, "$1 $2") + .replace("s’$2 ","s’ "); return output; }; var { typogrify } = typogr; From dd949ec1bbb05b81bafd5be9c57e479d333e1bdb Mon Sep 17 00:00:00 2001 From: Daniel Wood Date: Mon, 12 Aug 2024 13:32:29 -0400 Subject: [PATCH 17/18] merge master into lineage beta view (#69) * fixes smartypants bug; closes #64 * Update readme.rst Minor clarifications * add a note about publishing google sheets to s3 * update example config to ga4 --------- Co-authored-by: Brent Jones Co-authored-by: Alyson Hurt Co-authored-by: Hilary Fung <1105386+hilaryfung@users.noreply.github.com> --- config.json.example | 5 +++-- readme.rst | 14 +++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/config.json.example b/config.json.example index e1b9cb6..3bed8de 100644 --- a/config.json.example +++ b/config.json.example @@ -13,6 +13,7 @@ "prefix": "dailygraphics/graphics" } }, - // this is the NPR Visuals Google Analytics property. update to use your own. - "analyticsID": "UA-5828686-75" + // this is the NPR Visuals Google Analytics property. update to use your own. + "ga4ID": "G-LLLW9F9XPC", + "analyticsID": "UA-5828686-75" //legacy UA ID } diff --git a/readme.rst b/readme.rst index 3ab07b8..46773d8 100644 --- a/readme.rst +++ b/readme.rst @@ -54,12 +54,14 @@ Getting started in more detail Configuration for this project is split between ``config.json`` (an example of which is provided) for values that are organization-specific but not sensitive, and environment variables for values that should be confidential. +**Google API app** + We recognize that environment variables are not perfectly secure (since installed packages have access to them from the ``process`` global), but they're also impossible to check into GitHub accidentally. You should have set: * GOOGLE_OAUTH_CLIENT_ID * GOOGLE_OAUTH_CONSUMER_SECRET -The Google OAuth variables should match the client ID and secret for an API app that can access your account. `This post `_ has details on setting that up. +The Google OAuth variables should match the client ID and secret for an API app that can access your account. `This post `_ has details on setting that up. (Note: If you are an NPR News Apps user, you can skip this step. This API app already exists.) Alternatively, `service account authentication `_ is also supported. To create a service account and JSON key file, visit your project's `GCP web console `_ to get started. @@ -68,16 +70,22 @@ After creating the service account: 1. Grant write access on your Drive folder (``driveFolder`` in ``config.json``) to the service account email address. 2. Set GOOGLE_APPLICATION_CREDENTIALS to the file path of the JSON file containing your credentials. +**Amazon S3** + If you're deploying to S3, which is the default for the rig, you'll also need to set: * AWS_ACCESS_KEY_ID * AWS_SECRET_ACCESS_KEY * AWS_DEFAULT_REGION +**Additional directories** + In addition to the directory that contains this app, you'll also need two other directories. One is for the templates that are used to create each graphic (in the legacy rig, these were stored in the ``dailygraphics/graphic_templates`` folder). We provide a repo of templates used at NPR `here `_, and you should feel free to clone it. In the ``config.json file``, the "templateRoot" value should be the path to this folder. The other directory is for your graphics themselves, and it should be referenced with the "graphicsPath" key of your ``config.json`` file. This folder is also where you should install any libraries used by your graphics via NPM. For example, if you're using our templates, you'll want to run ``npm install d3-array d3-axis d3-scale d3-selection`` to get the most common D3 packages. +**Command-line arguments** + The server supports a number of command-line arguments to customize its behavior: * ``--port XXXX`` - sets the port that the server will listen on to XXXX. @@ -149,6 +157,10 @@ By default, the rig automatically casts values from strings to native JS types ( For example, to make sure that a "rankings" column is treated as a string of comma-separated numbers and not a single numerical value, you can rename it to "rankings:text". +**Publishing Sheets to S3** + +NPR has a Google Sheets add-on that publishes sheets to S3 as JSON. This is useful if you'll be updating the data or content of a graphic — but not its code — after publication. For instructions on how to set it up, read the `Hollerith documentation `_. + Template creation ----------------- From 6382a2927704d567f3d255d64f70af5bcb6ffa21 Mon Sep 17 00:00:00 2001 From: Daniel Wood Date: Mon, 7 Apr 2025 09:00:38 -0400 Subject: [PATCH 18/18] update classify and smarty to account for numbers passed in (#73) (#74) Co-authored-by: Alyson Hurt --- lib/templateFilters.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/templateFilters.js b/lib/templateFilters.js index 3478f80..9968456 100644 --- a/lib/templateFilters.js +++ b/lib/templateFilters.js @@ -78,7 +78,9 @@ var USPS_TO_AP_STATE = { var classify = function(str) { return str + .toString() // catch numbers that slip through .toLowerCase() + .trim() // trim out extra whitespace from beginning/end .replace(/\s+/g, "-") // Replace spaces with - .replace(/[^\w\-]+/g, "") // Remove all non-word chars .replace(/\-\-+/g, "-") // Replace multiple - with single - @@ -101,11 +103,15 @@ var ap_state = usps => USPS_TO_AP_STATE[usps]; var typogr = require("typogr"); var smarty = function(text) { + text = text + .toString() // catch numbers that slip through + .trim(); // trim out extra whitespace from beginning/end var typos = [typogr.amp, typogr.smartypants, typogr.widont, typogr.ord]; var output = typos.reduce((v, f) => f(v), text); output = output.replace(/–/g, "—") .replace(/([’']) ([”"])/g, "$1 $2") .replace("s’$2 ","s’ "); + return output; }; var { typogrify } = typogr;