Skip to content

Commit

Permalink
Adds page.rawInput for #1206
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Feb 9, 2024
1 parent a4f1fa8 commit 97d965a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
9 changes: 5 additions & 4 deletions src/Template.js
Original file line number Diff line number Diff line change
Expand Up @@ -649,11 +649,14 @@ class Template extends TemplateContent {
}

async getTemplates(data) {
let rawInput = await this.getPreRender();

// https://github.com/11ty/eleventy/issues/1206
data.page.rawInput = rawInput;

if (!Pagination.hasPagination(data)) {
await this.addComputedData(data);

let rawInput = await this.getPreRender();

let obj = {
template: this, // not on the docs but folks are relying on it
rawInput,
Expand All @@ -680,8 +683,6 @@ class Template extends TemplateContent {
let pageTemplates = await this.paging.getPageTemplates();
let objects = [];

let rawInput = await this.getPreRender();

for (let pageEntry of pageTemplates) {
await pageEntry.template.addComputedData(pageEntry.data);

Expand Down
12 changes: 6 additions & 6 deletions test/EleventyTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -771,9 +771,9 @@ test("Access to raw input of file (toJSON), issue #1206", async (t) => {
sortResultsBy(results, "content");

t.deepEqual(results.length, 2);
t.deepEqual(results[0].content, `This is the first template.`);
t.deepEqual(results[0].rawInput, `This is the first template.`);
t.deepEqual(results[1].content, `This is the second template.This is the first template.`);
t.deepEqual(results[0].content, `This is the first template.This is the first template.{{ page.rawInput }}`);
t.deepEqual(results[0].rawInput, `This is the first template.{{ page.rawInput }}`);
t.deepEqual(results[1].content, `This is the second template.This is the first template.{{ page.rawInput }}`);
t.deepEqual(results[1].rawInput, `This is the second template.{{ collections.tag1[0].rawInput }}`);
});

Expand All @@ -788,9 +788,9 @@ test("Access to raw input of file (dryRun), issue #1206", async (t) => {
sortResultsBy(results, "content");

t.deepEqual(results.length, 2);
t.deepEqual(results[0].content, `This is the first template.`);
t.deepEqual(results[0].rawInput, `This is the first template.`);
t.deepEqual(results[1].content, `This is the second template.This is the first template.`);
t.deepEqual(results[0].content, `This is the first template.This is the first template.{{ page.rawInput }}`);
t.deepEqual(results[0].rawInput, `This is the first template.{{ page.rawInput }}`);
t.deepEqual(results[1].content, `This is the second template.This is the first template.{{ page.rawInput }}`);
t.deepEqual(results[1].rawInput, `This is the second template.{{ collections.tag1[0].rawInput }}`);

rimrafSync("./test/stubs-1206/_site/");
Expand Down
2 changes: 1 addition & 1 deletion test/stubs-1206/page1.njk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
tags: tag1
---
This is the first template.
This is the first template.{{ page.rawInput }}

0 comments on commit 97d965a

Please sign in to comment.