mirror of https://github.com/sveltejs/svelte
parent
bc505161d1
commit
545ed7f0ed
@ -1,3 +1,16 @@
|
|||||||
export default function visitDocument() {
|
import { SsrGenerator } from '../index';
|
||||||
// noop
|
import Block from '../Block';
|
||||||
}
|
import { Node } from '../../../interfaces';
|
||||||
|
import stringifyAttributeValue from './shared/stringifyAttributeValue';
|
||||||
|
|
||||||
|
export default function visitDocument(
|
||||||
|
generator: SsrGenerator,
|
||||||
|
block: Block,
|
||||||
|
node: Node
|
||||||
|
) {
|
||||||
|
const title = node.attributes.find(attribute => attribute.type === 'Attribute' && attribute.name === 'title');
|
||||||
|
|
||||||
|
if (title) {
|
||||||
|
generator.append('${(__result.title = `' + stringifyAttributeValue(block, title.value) + '`, "")}');
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
import Block from '../../Block';
|
||||||
|
import { escape } from '../../../../utils/stringify';
|
||||||
|
import { Node } from '../../../../interfaces';
|
||||||
|
|
||||||
|
export default function stringifyAttributeValue(block: Block, chunks: Node[]) {
|
||||||
|
return chunks
|
||||||
|
.map((chunk: Node) => {
|
||||||
|
if (chunk.type === 'Text') {
|
||||||
|
return escape(chunk.data).replace(/"/g, '"');
|
||||||
|
}
|
||||||
|
|
||||||
|
block.contextualise(chunk.expression);
|
||||||
|
const { snippet } = chunk.metadata;
|
||||||
|
return '${' + snippet + '}';
|
||||||
|
})
|
||||||
|
.join('');
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"adjective": "custom"
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
<:Document title='a {{adjective}} title'/>
|
@ -0,0 +1 @@
|
|||||||
|
a custom title
|
Loading…
Reference in new issue