diff --git a/examples/article.html b/examples/article.html index 9743296..629e89b 100644 --- a/examples/article.html +++ b/examples/article.html @@ -32,20 +32,20 @@ { "author":"Chris Olah", "authorURL":"https://colah.github.io/", - "affiliation":"Google Brain", - "affiliationURL":"https://g.co/brain" - }, - { - "author":"Shan Carter", - "authorURL":"https://shancarter.com/", - "affiliation":"Google Brain", - "affiliationURL":"https://g.co/brain" + "affiliations": [{"name": "Google Brain", "url": "https://g.co/brain"}] }, { "author":"Ludwig Schubert", "authorURL":"https://shancarter.com/", - "affiliation":"Google Brain", - "affiliationURL":"https://g.co/brain" + "affiliations": [{"name": "Google Brain", "url": "https://g.co/brain"}] + }, + { + "author":"Shan Carter", + "authorURL":"https://shancarter.com/", + "affiliations": [ + {"name": "Google Brain", "url": "https://g.co/brain"}, + {"name": "NYT", "url": "https://nytimes.com"} + ] } ], "katex": { @@ -59,6 +59,7 @@

We often think of Momentum as a means of dampening oscillations and speeding up the iterations, leading to faster convergence. But it has other interesting behavior. It allows a larger range of step-sizes to be used, and creates its own oscillations. What is going on?

+ 1

A Brief Survey of Techniques

diff --git a/package.json b/package.json index 029c1b5..7cc793a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "distill-template", - "version": "2.2.19", + "version": "2.2.22", "description": "Template for creating Distill articles.", "main": "dist/template.v2.js", "bin": { diff --git a/src/components/d-byline.js b/src/components/d-byline.js index f2589b4..f03f14b 100644 --- a/src/components/d-byline.js +++ b/src/components/d-byline.js @@ -27,9 +27,9 @@ export function bylineTemplate(frontMatter) {
${author.name}
`}

- ${author.affiliationURL ? ` - ${author.affiliation}` : ` -

${author.affiliation}
`} + ${author.affiliations.map(affiliation => + affiliation.url ? `${affiliation.name}` : `
${affiliation.name}
` + ).join(', ')}

`).join('')} diff --git a/src/components/d-front-matter.js b/src/components/d-front-matter.js index 04e8f2a..41ad463 100644 --- a/src/components/d-front-matter.js +++ b/src/components/d-front-matter.js @@ -12,13 +12,36 @@ // See the License for the specific language governing permissions and // limitations under the License. +export function _moveLegacyAffiliationFormatIntoArray(frontMatter) { + // authors used to have propoerties "affiliation" and "affiliationURL". + // We now encourage using an array for affiliations containing objects with + // properties "name" and "url". + for (let author of frontMatter.authors) { + const hasOldStyle = Boolean(author.affiliation) + const hasNewStyle = Boolean(author.affiliations) + if (!hasOldStyle) continue; + if (hasNewStyle) { + console.warn(`Author ${author.author} has both old-style ("affiliation" & "affiliationURL") and new style ("affiliations") affiliation information!`) + } else { + let newAffiliation = { + "name": author.affiliation + } + if (author.affiliationURL) newAffiliation.url = author.affiliationURL; + author.affiliations = [newAffiliation]; + } + } + console.log(frontMatter) + return frontMatter +} + export function parseFrontmatter(element) { const scriptTag = element.querySelector('script'); if (scriptTag) { const type = scriptTag.getAttribute('type'); if (type.split('/')[1] == 'json') { const content = scriptTag.textContent; - return JSON.parse(content); + const parsed = JSON.parse(content); + return _moveLegacyAffiliationFormatIntoArray(parsed); } else { console.error('Distill only supports JSON frontmatter tags anymore; no more YAML.'); } diff --git a/src/front-matter.js b/src/front-matter.js index 03ee958..e256a5e 100644 --- a/src/front-matter.js +++ b/src/front-matter.js @@ -58,6 +58,7 @@ class Author { this.personalURL = object.authorURL; // 'https://colah.github.io' this.affiliation = object.affiliation; // 'Google Brain' this.affiliationURL = object.affiliationURL; // 'https://g.co/brain' + this.affiliations = object.affiliations || []; // new-style affiliations } // 'Chris'