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"));
diff --git a/lib/duplicateGraphic.js b/lib/duplicateGraphic.js
index f9b508d..c55dcf8 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,13 @@ module.exports = async function(config, original, slug) {
}
}
+ //load/create parent info
+ if (parent) {
+ manifest.parent.push(original)
+ } else {
+ manifest.parent = [original]
+ }
+
await fs.writeFile(manifestPath, JSON.stringify(manifest, null, 2));
console.log(`Duplicate of ${original} created as ${fullSlug} -- you got this!`);
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;
diff --git a/server/handlers/root.js b/server/handlers/root.js
index 5a6ba42..dc20886 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,32 @@ var getFolders = async function(dir) {
return matching;
};
+var getMetadata = async function(data,dir) {
+ var metadata = {};
+ 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) {
+ var template = manifest.templateType;
+ } else {
+ 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 +52,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/static/rootPage.js b/server/static/rootPage.js
index 04b8173..5bf93a5 100644
--- a/server/static/rootPage.js
+++ b/server/static/rootPage.js
@@ -1,20 +1,31 @@
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;
+
+ if (key == "template") {
+ value = value.replaceAll(" ","_")
+ }
+
var re = new RegExp(value);
- graphicItems.forEach(li => {
- var { slug } = li.dataset;
- li.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 d6451cb..28d346e 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 {
@@ -258,7 +259,7 @@ select {
}
.root-list .graphics-list {
- max-width: 400px;
+ /*max-width: 600px;*/
margin: 40px auto;
}
@@ -283,6 +284,41 @@ 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;
+}
+
+table tr.hide {
+ display: none;
+}
+
/* preview page */
.preview-page a.back {
diff --git a/server/templates/rootList.html b/server/templates/rootList.html
index fd0f8d9..371fe62 100644
--- a/server/templates/rootList.html
+++ b/server/templates/rootList.html
@@ -11,7 +11,8 @@
daily.graphics
-
+
+
|
+
+ Slug
+ |
+
+
+
+ Original template
+ |
+
+
+ Lineage
+ |
+
|---|---|---|
|
+
+ <%= g %>
+
+ |
+ <%= graphicMetadata[g].templateType.replace(/(_|^)(\w)/g, (_, p, s) => " " + s.toUpperCase()) %> | +<%= lineage %> | +