server-side <:Head>

pull/1024/head
Rich Harris 7 years ago
parent 50654fab88
commit ed44f7d1fa

@ -110,14 +110,14 @@ export default function ssr(
components.add(component);
}
var result = { title: null, addComponent };
var result = { head: '', addComponent };
var html = ${name}._render(result, state, options);
var cssCode = Array.from(components).map(c => c.css && c.css.code).filter(Boolean).join('\\n');
return {
html,
title: result.title,
head: result.head,
css: { code: cssCode, map: null },
toString() {
return result.html;

@ -2,17 +2,18 @@ import { SsrGenerator } from '../index';
import Block from '../Block';
import { Node } from '../../../interfaces';
import stringifyAttributeValue from './shared/stringifyAttributeValue';
import visit from '../visit';
export default function visitDocument(
generator: SsrGenerator,
block: Block,
node: Node
) {
throw new Error('TODO');
generator.append('${(__result.head += `');
// const title = node.attributes.find(attribute => attribute.type === 'Attribute' && attribute.name === 'title');
node.children.forEach((child: Node) => {
visit(generator, block, child);
});
// if (title) {
// generator.append('${(__result.title = `' + stringifyAttributeValue(block, title.value) + '`, "")}');
// }
generator.append('`, "")}');
}

@ -11,14 +11,14 @@ SvelteComponent.render = function(state, options = {}) {
components.add(component);
}
var result = { title: null, addComponent };
var result = { head: '', addComponent };
var html = SvelteComponent._render(result, state, options);
var cssCode = Array.from(components).map(c => c.css && c.css.code).filter(Boolean).join('\n');
return {
html,
title: result.title,
head: result.head,
css: { code: cssCode, map: null },
toString() {
return result.html;

@ -13,14 +13,14 @@ SvelteComponent.render = function(state, options = {}) {
components.add(component);
}
var result = { title: null, addComponent };
var result = { head: '', addComponent };
var html = SvelteComponent._render(result, state, options);
var cssCode = Array.from(components).map(c => c.css && c.css.code).filter(Boolean).join('\n');
return {
html,
title: result.title,
head: result.head,
css: { code: cssCode, map: null },
toString() {
return result.html;

@ -1,6 +1,4 @@
export default {
solo: true,
data: {
adjective: 'custom'
},

@ -59,7 +59,7 @@ describe("ssr", () => {
const data = tryToLoadJson(`${dir}/data.json`);
const { html, css, title } = component.render(data);
const { html, css, head } = component.render(data);
fs.writeFileSync(`${dir}/_actual.html`, html);
if (css.code) fs.writeFileSync(`${dir}/_actual.css`, css.code);
@ -70,10 +70,11 @@ describe("ssr", () => {
expectedCss.replace(/^\s+/gm, "")
);
if (fs.existsSync(`${dir}/title.txt`)) {
assert.equal(
title,
fs.readFileSync(`${dir}/title.txt`, 'utf-8')
if (fs.existsSync(`${dir}/_expected-head.html`)) {
fs.writeFileSync(`${dir}/_actual-head.html`, head);
assert.htmlEqual(
head,
fs.readFileSync(`${dir}/_expected-head.html`, 'utf-8')
);
}

Loading…
Cancel
Save