Skip to content

Commit

Permalink
Fixes #941, Fixes #816, Fixes #289.
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Feb 17, 2020
1 parent 55e92c2 commit 4b09b43
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 280 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"homepage": "https://www.11ty.dev/",
"ava": {
"babel": true,
"failFast": true,
"failFast": false,
"files": [
"./test/*.js"
],
Expand Down
62 changes: 21 additions & 41 deletions src/Template.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Template extends TemplateContent {
}

getLayout(layoutKey) {
if(!this._layout || layoutKey !== this._layoutKey) {
if (!this._layout || layoutKey !== this._layoutKey) {
this._layoutKey = layoutKey;
this._layout = TemplateLayout.getTemplate(
layoutKey,
Expand All @@ -85,7 +85,7 @@ class Template extends TemplateContent {
}

async getLayoutChain() {
if(!this._layout) {
if (!this._layout) {
await this.getData();
}

Expand Down Expand Up @@ -159,7 +159,6 @@ class Template extends TemplateContent {
return link.toHref();
}

// TODO check for conflicts, see if file already exists?
async getOutputPath(data) {
let uri = await this.getOutputLink(data);

Expand Down Expand Up @@ -294,42 +293,6 @@ class Template extends TemplateContent {
return data;
}

async addPageRenderedData(data) {
if (!("page" in data)) {
data.page = {};
}

let newUrl = await this.getOutputHref(data);
if ("page" in data && "url" in data.page) {
if (data.page.url !== newUrl) {
debug(
"Warning: data.page.url is in use (%o) will be overwritten with: %o",
data.page.url,
newUrl
);
}
}

data.page.url = newUrl;
data.page.outputPath = await this.getOutputPath(data);

return data;
}

// getData (with renderData and page.url added)
async getRenderedData() {
let data = await this.getData();
data = await this.addPageRenderedData(data);

if (data.renderData) {
data.renderData = await this.mapDataAsRenderedTemplates(
data.renderData,
data
);
}
return data;
}

async renderLayout(tmpl, tmplData) {
let layoutKey = tmplData[tmpl.config.keys.layout];
let layout = this.getLayout(layoutKey);
Expand All @@ -354,10 +317,12 @@ class Template extends TemplateContent {
return super.render(str, data, bypassMarkdown);
}

// TODO at least some of this isn’t being used in the normal build
// Render is used for `renderData` and `permalink` but otherwise `renderPageEntry` is being used
async render(data) {
debugDev("%o render()", this.inputPath);
if (!data) {
data = await this.getRenderedData();
throw new Error("`data` needs to be passed into render()");
}

if (!this.wrapWithLayouts && data[this.config.keys.layout]) {
Expand Down Expand Up @@ -407,6 +372,13 @@ class Template extends TemplateContent {
data.page.url = await this.getOutputHref(data);
data.page.outputPath = await this.getOutputPath(data);

if ("renderData" in data) {
data.renderData = await this.mapDataAsRenderedTemplates(
data.renderData,
data
);
}

results.push({
template: this,
inputPath: this.inputPath,
Expand Down Expand Up @@ -438,7 +410,7 @@ class Template extends TemplateContent {
let pageNumber = 0;
for (let page of templates) {
// TODO try to reuse data instead of a new copy
let pageData = await page.getRenderedData();
let pageData = Object.assign({}, await page.getData());

// Issue #115
if (data.collections) {
Expand All @@ -448,6 +420,13 @@ class Template extends TemplateContent {
pageData.page.url = await page.getOutputHref(pageData);
pageData.page.outputPath = await page.getOutputPath(pageData);

if ("renderData" in pageData) {
pageData.renderData = await page.mapDataAsRenderedTemplates(
pageData.renderData,
pageData
);
}

results.push({
template: page,
inputPath: this.inputPath,
Expand Down Expand Up @@ -560,6 +539,7 @@ class Template extends TemplateContent {
return Promise.all(promises);
}

// TODO is this still used by anything but tests?
async write(outputPath, data) {
let templates = await this.getRenderedTemplates(data);
let promises = [];
Expand Down
2 changes: 2 additions & 0 deletions src/TemplateMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,11 +483,13 @@ class TemplateMap {

populateCollectionsWithContent() {
for (let collectionName in this.collectionsData) {
// skip custom collections set in configuration files that have arbitrary types
if (!Array.isArray(this.collectionsData[collectionName])) {
continue;
}

for (let item of this.collectionsData[collectionName]) {
// skip custom collections set in configuration files that have arbitrary types
if (!isPlainObject(item) || !("inputPath" in item)) {
continue;
}
Expand Down
Loading

0 comments on commit 4b09b43

Please sign in to comment.