Skip to content

Commit

Permalink
generate __data.json files as siblings of .html files
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Dec 12, 2023
1 parent ac6c3cb commit b0ac9ef
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/happy-beds-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': major
---

breaking: generate `__data.json` files as sibling to `.html` files
2 changes: 1 addition & 1 deletion packages/kit/src/runtime/server/page/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export async function render_page(event, page, options, manifest, state, resolve

// it's crucial that we do this before returning the non-SSR response, otherwise
// SvelteKit will erroneously believe that the path has been prerendered,
// causing functions to be omitted from the manifesst generated later
// causing functions to be omitted from the manifest generated later
const should_prerender = get_option(nodes, 'prerender') ?? false;
if (should_prerender) {
const mod = leaf_node.server;
Expand Down
8 changes: 7 additions & 1 deletion packages/kit/src/utils/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,18 +208,24 @@ function allow_nodejs_console_log(url) {
}

const DATA_SUFFIX = '/__data.json';
const HTML_DATA_SUFFIX = '.html__data.json';

/** @param {string} pathname */
export function has_data_suffix(pathname) {
return pathname.endsWith(DATA_SUFFIX);
return pathname.endsWith(DATA_SUFFIX) || pathname.endsWith(HTML_DATA_SUFFIX);
}

/** @param {string} pathname */
export function add_data_suffix(pathname) {
if (pathname.endsWith('.html')) return pathname.replace(/\.html$/, HTML_DATA_SUFFIX);
return pathname.replace(/\/$/, '') + DATA_SUFFIX;
}

/** @param {string} pathname */
export function strip_data_suffix(pathname) {
if (pathname.endsWith(HTML_DATA_SUFFIX)) {
return pathname.slice(0, -HTML_DATA_SUFFIX.length) + '.html';
}

return pathname.slice(0, -DATA_SUFFIX.length);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function load() {
return {
message: 'hello'
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
export let data;
</script>

<h1>{data.message}</h1>

0 comments on commit b0ac9ef

Please sign in to comment.