Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug/issue 1351 better handling of frontmatter syntax for JSON.stringify in SSR page bundles #1362

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/cli/src/lifecycles/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { hashString } from '../lib/hashing-utils.js';
import { checkResourceExists, mergeResponse, normalizePathnameForWindows, trackResourcesForRoute } from '../lib/resource-utils.js';
import path from 'path';
import { rollup } from 'rollup';
import { pruneGraph } from '../lib/content-utils.js';

async function interceptPage(url, request, plugins, body) {
let response = new Response(body, {
Expand Down Expand Up @@ -304,8 +305,8 @@ async function bundleSsrPages(compilation, optimizePlugins) {
const moduleUrl = new URL('${relativeDepth}${pagesPathDiff}${pagePath.replace('./', '')}', import.meta.url);

export async function handler(request) {
const compilation = JSON.parse('${JSON.stringify(compilation)}');
const page = JSON.parse('${JSON.stringify(page)}');
const compilation = JSON.parse(\`${JSON.stringify({ ...compilation, graph: pruneGraph(compilation.graph) }).replace(/\\"/g, '&quote').replace(/\\n/g, '')}\`);
const page = JSON.parse(\`${JSON.stringify(pruneGraph([page])[0]).replace(/\\"/g, '&quote').replace(/\\n/g, '')}\`);
const data = await executeRouteModule({ moduleUrl, compilation, page, request });
let staticHtml = \`${staticHtml}\`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,25 @@ describe('Serve Greenwood With: ', function() {
});
});

// https://github.com/ProjectEvergreen/greenwood/issues/1351
describe('Serve command with HTML route response for the about page using various frontmatter syntaxes', function() {
let response;
let dom;

before(async function() {
response = await fetch(`${hostname}/about/`);
const body = await response.clone().text();
dom = new JSDOM(body);
});

it('should have the expected output for the page', function() {
const headings = dom.window.document.querySelectorAll('body > h1');

expect(headings.length).to.equal(1);
expect(headings[0].textContent).to.equal('Welcome to the about page!');
});
});

describe('Serve command with HTML route response for artists page using "get" functions', function() {
let response;
let dom;
Expand Down
11 changes: 9 additions & 2 deletions packages/cli/test/cases/serve.default.ssr/src/pages/about.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## About Page
---
title: |
Greenwood's Super Cool About Page
imports:
- ../components/counter.js type="module"
sidebar:
order: 1
---

Lorum Ipsum.
# Welcome to the about page!
Loading