From 07dee84d2b01bad59ffa813a40d29aa7a4b67a48 Mon Sep 17 00:00:00 2001 From: Christopher Olah Date: Sat, 7 Jan 2017 12:45:43 -0800 Subject: [PATCH] add expand data --- components/expand-data.js | 33 +++++++++++++++++++++++++++++++++ index.js | 2 ++ 2 files changed, 35 insertions(+) create mode 100644 components/expand-data.js diff --git a/components/expand-data.js b/components/expand-data.js new file mode 100644 index 0000000..9f3aa46 --- /dev/null +++ b/components/expand-data.js @@ -0,0 +1,33 @@ +export default function(dom, data) { + + // paths + //data.distillPath = post.distillPath; + //data.githubPath = post.githubPath; + //data.url = "http://distill.pub/" + post.distillPath; + //data.githubUrl = "https://github.com/" + post.githubPath; + + // Homepage + //data.homepage = !post.noHomepage; + + // Dates + // TODO: fix updated date + if (data.published) { + data.publishedDate = new Date(data.published); + data.updatedDate = new Date(data.published || data.updated); + + //let RFC = d3.timeFormat("%a, %d %b %Y %H:%M:%S %Z"); + let months = ["Jan", "Feb", "March", "April", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec"]; + let zeroPad = (n) => { return n < 10 ? "0" + n : n; }; + //data.publishedDateRFC = RFC(data.publishedDate); + data.publishedYear = data.publishedDate.getFullYear(); + data.publishedMonth = months[data.publishedDate.getMonth()]; + data.publishedDay = data.publishedDate.getDate(); + data.publishedMonthPadded = zeroPad(data.publishedDate.getMonth() + 1); + data.publishedDayPadded = zeroPad(data.publishedDate.getDate()); + data.volume = data.publishedDate.getFullYear() - 2015; + data.issue = data.publishedDate.getMonth() + 1; + } + + + +} diff --git a/index.js b/index.js index 07b98d0..d9c9459 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,7 @@ import html from "./components/html"; import styles from "./components/styles"; import frontMatter from "./components/front-matter"; import bibliography from "./components/bibliography"; +import expandData from "./components/expand-data"; import meta from "./components/meta"; import header from "./components/header"; import appendix from "./components/appendix"; @@ -18,6 +19,7 @@ function render(dom, data) { document.addEventListener("DOMContentLoaded", function(event) { frontMatter(dom, data); bibliography(dom, data); + expandData(dom, data); meta(dom, data); header(dom, data); appendix(dom, data);