Skip to content

Commit

Permalink
Merge pull request #45 from mydea/fn/fix-no-prerender-empty
Browse files Browse the repository at this point in the history
Ensure empty file prerender state works no matter how meta tag looks
  • Loading branch information
mydea authored Mar 9, 2022
2 parents 1582279 + 1b58423 commit 6c53ccd
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = function fixPrerenderInEmptyFile(emptyFileContent) {
return emptyFileContent.replace(
'<meta name="prerender-config" content="should-prerender"',
'<meta name="prerender-config" content="skip"'
);
};
7 changes: 3 additions & 4 deletions packages/ember-build-prerender/lib/utils/merge-prerender.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const fs = require('fs-extra');
const fixPrerenderInEmptyFile = require('./fix-prerender-in-empty-file');
const path = require('path');

module.exports = async function mergePrerender({
Expand All @@ -14,10 +15,8 @@ module.exports = async function mergePrerender({

// Remove prerender config from empty file
let emptyFileContent = await fs.readFile(emptyFilePath, 'utf-8');
emptyFileContent = emptyFileContent.replace(
'<meta name="prerender-config" content="should-prerender"></meta>',
'<meta name="prerender-config" content="skip"></meta>'
);
emptyFileContent = fixPrerenderInEmptyFile(emptyFileContent);

await fs.writeFile(emptyFilePath, emptyFileContent, 'utf-8');

await fs.remove(buildDir);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const { expect } = require('chai');
const fixPrerenderInEmptyFile = require('ember-build-prerender/lib/utils/fix-prerender-in-empty-file');

describe('fix-prerender-in-empty-file', function () {
it('it works with empty string', async function () {
let source = ``;
let expected = ``;
let result = fixPrerenderInEmptyFile(source);

expect(result).to.equal(expected);
});

it('it works with self-closing tag', async function () {
let source = `
<meta name="prerender-config" content="should-prerender" />
<meta name="other" content="should-prerender" />`;
let expected = `
<meta name="prerender-config" content="skip" />
<meta name="other" content="should-prerender" />`;
let result = fixPrerenderInEmptyFile(source);

expect(result).to.equal(expected);
});

it('it works with closing tag', async function () {
let source = `
<meta name="prerender-config" content="should-prerender"></meta>
<meta name="other" content="should-prerender"></meta>`;
let expected = `
<meta name="prerender-config" content="skip"></meta>
<meta name="other" content="should-prerender"></meta>`;
let result = fixPrerenderInEmptyFile(source);

expect(result).to.equal(expected);
});

it('it works with only open tag', async function () {
let source = `
<meta name="prerender-config" content="should-prerender">
<meta name="other" content="should-prerender">`;
let expected = `
<meta name="prerender-config" content="skip">
<meta name="other" content="should-prerender">`;
let result = fixPrerenderInEmptyFile(source);

expect(result).to.equal(expected);
});
});

0 comments on commit 6c53ccd

Please sign in to comment.