Skip to content

Commit

Permalink
[docs] LayoutLoad -> LayoutServerLoad (#6409)
Browse files Browse the repository at this point in the history
Also include filename in diff blocks
  • Loading branch information
Rich-Harris authored Aug 30, 2022
1 parent 735e389 commit 9592539
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion documentation/docs/05-load.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ To redirect users, use the `redirect` helper from `@sveltejs/kit` to specify the
-import { error } from '@sveltejs/kit';
+import { error, redirect } from '@sveltejs/kit';

/** @type {import('./$types').LayoutLoad} */
/** @type {import('./$types').LayoutServerLoad} */
export function load({ locals }) {
if (!locals.user) {
- throw error(401, 'not logged in');
Expand Down
16 changes: 8 additions & 8 deletions sites/kit.svelte.dev/src/lib/docs/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,7 @@ export async function read_file(dir, file) {
);

// preserve blank lines in output (maybe there's a more correct way to do this?)
html = `<div class="code-block">${
options.file ? `<h5>${options.file}</h5>` : ''
}${html.replace(/<div class='line'><\/div>/g, '<div class="line"> </div>')}</div>`;
html = html.replace(/<div class='line'><\/div>/g, '<div class="line"> </div>');
} else if (language === 'diff') {
const lines = source.split('\n').map((content) => {
let type = null;
Expand All @@ -170,23 +168,25 @@ export async function read_file(dir, file) {
};
});

html = `<div class="code-block"><pre class="language-diff"><code>${lines
html = `<pre class="language-diff"><code>${lines
.map((line) => {
if (line.type) return `<span class="${line.type}">${line.content}\n</span>`;
return line.content + '\n';
})
.join('')}</code></pre></div>`;
.join('')}</code></pre>`;
} else {
const plang = languages[language];
const highlighted = plang
? PrismJS.highlight(source, PrismJS.languages[plang], language)
: source.replace(/[&<>]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;' }[c]));

html = `<div class="code-block">${
options.file ? `<h5>${options.file}</h5>` : ''
}<pre class='language-${plang}'><code>${highlighted}</code></pre></div>`;
html = `<pre class='language-${plang}'><code>${highlighted}</code></pre>`;
}

html = `<div class="code-block">${
options.file ? `<h5>${options.file}</h5>` : ''
}${html}</div>`;

type_regex.lastIndex = 0;

return html
Expand Down

0 comments on commit 9592539

Please sign in to comment.