mirror of https://github.com/sveltejs/svelte
update API reference docs (#2206)
parent
a824a6dd6f
commit
a07eac432a
@ -0,0 +1,9 @@
|
|||||||
|
---
|
||||||
|
title: Before we begin
|
||||||
|
---
|
||||||
|
|
||||||
|
> Temporary note: This document is a work-in-progress. Please forgive any missing or misleading parts, and don't be shy about asking for help in the [Discord chatroom](https://discord.gg/yy75DKs). The [tutorial](tutorial) is more complete; start there.
|
||||||
|
|
||||||
|
This page contains detailed API reference documentation. It's intended to be a resource for people who already have some familiarity with Svelte.
|
||||||
|
|
||||||
|
If that's not you (yet), you may prefer to visit the [interactive tutorial](tutorial) or the [examples](examples) before consulting this reference.
|
@ -0,0 +1,193 @@
|
|||||||
|
---
|
||||||
|
title: Component format
|
||||||
|
---
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Components are the building blocks of Svelte applications. They are written into `.svelte` files, using a superset of HTML.
|
||||||
|
|
||||||
|
All three sections — script, styles and markup — are optional.
|
||||||
|
|
||||||
|
```html
|
||||||
|
<script>
|
||||||
|
// logic goes here
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
/* styles go here */
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<!-- markup (zero or more items) goes here -->
|
||||||
|
```
|
||||||
|
|
||||||
|
### <script>
|
||||||
|
|
||||||
|
A `<script>` block contains JavaScript that runs when a component instance is created. Variables declared (or imported) at the top level are 'visible' from the component's markup. There are four additional rules:
|
||||||
|
|
||||||
|
#### 1. `export` creates a component prop
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Svelte uses the `export` keyword to mark a variable declaration as a *property* or *prop*, which means it becomes accessible to consumers of the component:
|
||||||
|
|
||||||
|
```html
|
||||||
|
<script>
|
||||||
|
// these properties can be set externally
|
||||||
|
export let foo;
|
||||||
|
export let bar = 'optional default value';
|
||||||
|
|
||||||
|
// Values that are passed in as props
|
||||||
|
// are immediately available
|
||||||
|
console.log(foo, bar);
|
||||||
|
|
||||||
|
// function declarations cannot be set externally,
|
||||||
|
// but can be accessed from outside
|
||||||
|
export function instanceMethod() {
|
||||||
|
alert(foo);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 2. Assignments are 'reactive'
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
To change component state and trigger a re-render, just assign to a locally declared variable.
|
||||||
|
|
||||||
|
Update expressions (`count += 1`) and property assignments (`obj.x = y`) have the same effect.
|
||||||
|
|
||||||
|
```html
|
||||||
|
<script>
|
||||||
|
let count = 0;
|
||||||
|
|
||||||
|
function handleClick () {
|
||||||
|
// calling this function will trigger a re-render
|
||||||
|
// if the markup references `count`
|
||||||
|
count = count + 1;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 3. `$:` marks a statement as reactive
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Any top-level statement (i.e. not inside a block or a function) can be made reactive by prefixing it with the `$:` label. Reactive statements run immediately before the component updates, whenever the values that they depend on have changed.
|
||||||
|
|
||||||
|
```html
|
||||||
|
<script>
|
||||||
|
export let title;
|
||||||
|
|
||||||
|
// this will update `document.title` whenever
|
||||||
|
// the `title` prop changes
|
||||||
|
$: document.title = title;
|
||||||
|
|
||||||
|
$: {
|
||||||
|
console.log(`multiple statements can be combined`);
|
||||||
|
console.log(`the current title is ${title}`);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
If a statement consists entirely of an assignment to an undeclared variable, Svelte will inject a `let` declaration on your behalf.
|
||||||
|
|
||||||
|
```html
|
||||||
|
<script>
|
||||||
|
export let num;
|
||||||
|
|
||||||
|
// we don't need to declare `squared` and `cubed`
|
||||||
|
// — Svelte does it for us
|
||||||
|
$: squared = num * num;
|
||||||
|
$: cubed = squared * num;
|
||||||
|
</script>
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 4. Prefix stores with `$` to access their values
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Any time you have a reference to a store, you can access its value inside a component by prefixing it with the `$` character. This causes Svelte to declare the prefixed variable, and set up a store subscription that will be unsubscribed when appropriate.
|
||||||
|
|
||||||
|
Note that the store must be declared at the top level of the component — not inside an `if` block or a function, for example.
|
||||||
|
|
||||||
|
Local variables (that do not represent store values) must *not* have a `$` prefix.
|
||||||
|
|
||||||
|
```html
|
||||||
|
<script>
|
||||||
|
import { writable } from 'svelte/store';
|
||||||
|
|
||||||
|
const count = writable(0);
|
||||||
|
console.log($count); // logs 0
|
||||||
|
|
||||||
|
count.set(1);
|
||||||
|
console.log($count); // logs 1
|
||||||
|
</script>
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### <script context="module">
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
A `<script>` tag with a `context="module"` attribute runs once when the module first evaluates, rather than for each component instance. Values declared in this block are accessible from a regular `<script>` (and the component markup) but not vice versa.
|
||||||
|
|
||||||
|
You can `export` bindings from this block, and they will become exports of the compiled module.
|
||||||
|
|
||||||
|
You cannot `export default`, since the default export is the component itself.
|
||||||
|
|
||||||
|
```html
|
||||||
|
<script context="module">
|
||||||
|
let totalComponents = 0;
|
||||||
|
|
||||||
|
// this allows an importer to do e.g.
|
||||||
|
// `import Example, { alertTotal } from './Example.svelte'`
|
||||||
|
export function alertTotal() {
|
||||||
|
alert(totalComponents);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
totalComponents += 1;
|
||||||
|
console.log(`total number of times this component has been created: ${totalComponents}`);
|
||||||
|
</script>
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### <style>
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
CSS inside a `<style>` block will be scoped to that component.
|
||||||
|
|
||||||
|
This works by adding a class to affected elements, which is based on a hash of the component styles (e.g. `svelte-123xyz`).
|
||||||
|
|
||||||
|
```html
|
||||||
|
<style>
|
||||||
|
p {
|
||||||
|
/* this will only affect <p> elements in this component */
|
||||||
|
color: burlywood;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
To apply styles to a selector globally, use the `:global(...)` modifier.
|
||||||
|
|
||||||
|
```html
|
||||||
|
<style>
|
||||||
|
:global(body) {
|
||||||
|
/* this will apply to <body> */
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
div :global(strong) {
|
||||||
|
/* this will apply to all <strong> elements, in any
|
||||||
|
component, that are inside <div> elements belonging
|
||||||
|
to this component */
|
||||||
|
color: goldenrod;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
```
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,291 @@
|
|||||||
|
---
|
||||||
|
title: Compile time
|
||||||
|
---
|
||||||
|
|
||||||
|
Typically, you won't interact with the Svelte compiler directly, but will instead integrate it into your build system using a bundler plugin:
|
||||||
|
|
||||||
|
* [rollup-plugin-svelte](https://github.com/rollup/rollup-plugin-svelte) for users of [Rollup](https://rollupjs.org)
|
||||||
|
* [svelte-loader](https://github.com/sveltejs/svelte-loader) for users of [webpack](https://webpack.js.org)
|
||||||
|
* [parcel-plugin-svelte](https://github.com/DeMoorJasper/parcel-plugin-svelte) for users of [Parcel](https://parceljs.org/)
|
||||||
|
|
||||||
|
Nonetheless, it's useful to understand how to use the compiler, since bundler plugins generally expose compiler options to you.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### svelte.compile
|
||||||
|
|
||||||
|
```js
|
||||||
|
result: {
|
||||||
|
js,
|
||||||
|
css,
|
||||||
|
ast,
|
||||||
|
warnings,
|
||||||
|
vars,
|
||||||
|
stats
|
||||||
|
} = svelte.compile(source: string, options?: {...})
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
This is where the magic happens. `svelte.compile` takes your component source code, and turns it into a JavaScript module that exports a class.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const svelte = require('svelte/compiler');
|
||||||
|
|
||||||
|
const result = svelte.compile(source, {
|
||||||
|
// options
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
The following options can be passed to the compiler. None are required:
|
||||||
|
|
||||||
|
<!-- | option | type | default
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `filename` | string | `null`
|
||||||
|
| `name` | string | `"Component"`
|
||||||
|
| `format` | `"esm"` or `"cjs"` | `"esm"`
|
||||||
|
| `generate` | `"dom"` or `"ssr"` | `"dom"`
|
||||||
|
| `dev` | boolean | `false`
|
||||||
|
| `immutable` | boolean | `false`
|
||||||
|
| `hydratable` | boolean | `false`
|
||||||
|
| `legacy` | boolean | `false`
|
||||||
|
| `customElement` | boolean | `false`
|
||||||
|
| `tag` | string | null
|
||||||
|
| `accessors` | boolean | `false`
|
||||||
|
| `css` | boolean | `true`
|
||||||
|
| `preserveComments` | boolean | `false`
|
||||||
|
| `preserveWhitespace` | boolean | `false`
|
||||||
|
| `outputFilename` | string | `null`
|
||||||
|
| `cssOutputFilename` | string | `null`
|
||||||
|
| `sveltePath` | string | `"svelte"` -->
|
||||||
|
|
||||||
|
| option | default | description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `filename` | `null` | `string` used for debugging hints and sourcemaps. Your bundler plugin will set it automatically.
|
||||||
|
| `name` | `"Component"` | `string` that sets the name of the resulting JavaScript class (though the compiler will rename it if it would otherwise conflict with other variables in scope). It will normally be inferred from `filename`.
|
||||||
|
| `format` | `"esm"` | If `"esm"`, creates a JavaScript module (with `import` and `export`). If `"cjs"`, creates a CommonJS module (with `require` and `module.exports`), which is useful in some server-side rendering situations or for testing.
|
||||||
|
| `generate` | `"dom"` | If `"dom"`, Svelte emits a JavaScript class for mounting to the DOM. If `"ssr"`, Svelte emits an object with a `render` method suitable for server-side rendering. If `false`, no JavaScript or CSS is returned; just metadata.
|
||||||
|
| `dev` | `false` | If `true`, causes extra code to be added to components that will perform runtime checks and provide debugging information during development.
|
||||||
|
| `immutable` | `false` | If `true`, tells the compiler that you promise not to mutate any objects. This allows it to be less conservative about checking whether values have changed.
|
||||||
|
| `hydratable` | `false` | If `true`, enables the `hydrate: true` runtime option, which allows a component to upgrade existing DOM rather than creating new DOM from scratch.
|
||||||
|
| `legacy` | `false` | If `true`, generates code that will work in IE9 and IE10, which don't support things like `element.dataset`.
|
||||||
|
| `accessors` | `false` | If `true`, getters and setters will be created for the component's props. If `false`, they will only be created for readonly exported values (i.e. those declared with `const`, `class` and `function`). If compiling with `customElement: true` this option defaults to `true`.
|
||||||
|
| `customElement` | `false` | If `true`, tells the compiler to generate a custom element constructor instead of a regular Svelte component.
|
||||||
|
| `tag` | `null` | A `string` that tells Svelte what tag name to register the custom element with. It must be a lowercase alphanumeric string with at least one hyphen, e.g. `"my-element"`.
|
||||||
|
| `css` | `true` | If `true`, styles will be included in the JavaScript class and injected at runtime. It's recommended that you set this to `false` and use the CSS that is statically generated, as it will result in smaller JavaScript bundles and better performance.
|
||||||
|
| `preserveComments` | `false` | If `true`, your HTML comments will be preserved during server-side rendering. By default, they are stripped out.
|
||||||
|
| `preserveWhitespace` | `false` | If `true`, whitespace inside and between elements is kept as you typed it, rather than optimised by Svelte.
|
||||||
|
| `outputFilename` | `null` | A `string` used for your JavaScript sourcemap.
|
||||||
|
| `cssOutputFilename` | `null` | A `string` used for your CSS sourcemap.
|
||||||
|
| `sveltePath` | `"svelte"` | The location of the `svelte` package. Any imports from `svelte` or `svelte/[module]` will be modified accordingly.
|
||||||
|
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
The returned `result` object contains the code for your component, along with useful bits of metadata.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const {
|
||||||
|
js,
|
||||||
|
css,
|
||||||
|
ast,
|
||||||
|
warnings,
|
||||||
|
vars,
|
||||||
|
stats
|
||||||
|
} = svelte.compile(source);
|
||||||
|
```
|
||||||
|
|
||||||
|
* `js` and `css` are obejcts with the following properties:
|
||||||
|
* `code` is a JavaScript string
|
||||||
|
* `map` is a sourcemap with additional `toString()` and `toUrl()` convenience methods
|
||||||
|
* `ast` is an abstract syntax tree representing the structure of your component.
|
||||||
|
* `warnings` is an array of warning objects that were generated during compilation. Each warning has several properties:
|
||||||
|
* `code` is a string identifying the category of warning
|
||||||
|
* `message` describes the issue in human-readable terms
|
||||||
|
* `start` and `end`, if the warning relates to a specific location, are objects with `line`, `column` and `character` properties
|
||||||
|
* `frame`, if applicable, is a string highlighting the offending code with line numbers
|
||||||
|
* `vars` is an array of the component's declarations, used by [eslint-plugin-svelte3](https://github.com/sveltejs/eslint-plugin-svelte3) for example. Each variable has several properties:
|
||||||
|
* `name` is self-explanatory
|
||||||
|
* `export_name` is the name the value is exported as, if it is exported (will match `name` unless you do `export...as`)
|
||||||
|
* `injected` is `true` if the declaration is injected by Svelte, rather than in the code you wrote
|
||||||
|
* `module` is `true` if the value is declared in a `context="module"` script
|
||||||
|
* `mutated` is `true` if the value's properties are assigned to inside the component
|
||||||
|
* `reassigned` is `true` if the value is reassigned inside the component
|
||||||
|
* `referenced` is `true` if the value is used outside the declaration
|
||||||
|
* `writable` is `true` if the value was declared with `let` or `var` (but not `const`, `class` or `function`)
|
||||||
|
* `stats` is an object used by the Svelte developer team for diagnosing the compiler. Avoid relying on it to stay the same!
|
||||||
|
|
||||||
|
|
||||||
|
<!--
|
||||||
|
|
||||||
|
```js
|
||||||
|
compiled: {
|
||||||
|
// `map` is a v3 sourcemap with toString()/toUrl() methods
|
||||||
|
js: { code: string, map: {...} },
|
||||||
|
css: { code: string, map: {...} },
|
||||||
|
ast: {...}, // ESTree-like syntax tree for the component, including HTML, CSS and JS
|
||||||
|
warnings: Array<{
|
||||||
|
code: string,
|
||||||
|
message: string,
|
||||||
|
filename: string,
|
||||||
|
pos: number,
|
||||||
|
start: { line: number, column: number },
|
||||||
|
end: { line: number, column: number },
|
||||||
|
frame: string,
|
||||||
|
toString: () => string
|
||||||
|
}>,
|
||||||
|
vars: Array<{
|
||||||
|
name: string,
|
||||||
|
export_name: string,
|
||||||
|
injected: boolean,
|
||||||
|
module: boolean,
|
||||||
|
mutated: boolean,
|
||||||
|
reassigned: boolean,
|
||||||
|
referenced: boolean,
|
||||||
|
writable: boolean
|
||||||
|
}>,
|
||||||
|
stats: {
|
||||||
|
timings: { [label]: number }
|
||||||
|
}
|
||||||
|
} = svelte.compile(source: string, options?: {...})
|
||||||
|
```
|
||||||
|
|
||||||
|
-->
|
||||||
|
|
||||||
|
|
||||||
|
### svelte.preprocess
|
||||||
|
|
||||||
|
```js
|
||||||
|
result: {
|
||||||
|
code: string,
|
||||||
|
dependencies: Array<string>
|
||||||
|
} = svelte.preprocess(
|
||||||
|
source: string,
|
||||||
|
preprocessors: Array<{
|
||||||
|
markup?: (input: { source: string, filename: string }) => Promise<{
|
||||||
|
code: string,
|
||||||
|
dependencies?: Array<string>
|
||||||
|
}>,
|
||||||
|
script?: (input: { source: string, attributes: Record<string, string>, filename: string }) => Promise<{
|
||||||
|
code: string,
|
||||||
|
dependencies?: Array<string>
|
||||||
|
}>,
|
||||||
|
style?: (input: { source: string, attributes: Record<string, string>, filename: string }) => Promise<{
|
||||||
|
code: string,
|
||||||
|
dependencies?: Array<string>
|
||||||
|
}>
|
||||||
|
}>,
|
||||||
|
options?: {
|
||||||
|
filename?: string
|
||||||
|
}
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
The `preprocess` function provides convenient hooks for arbitrarily transforming component source code. For example, it can be used to convert a `<style lang="sass">` block into vanilla CSS.
|
||||||
|
|
||||||
|
The first argument is the component source code. The second is an array of *preprocessors* (or a single preprocessor, if you only have one), where a preprocessor is an object with `markup`, `script` and `style` functions, each of which is optional.
|
||||||
|
|
||||||
|
Each `markup`, `script` or `style` function must return an object (or a Promise that resolves to an object) with a `code` property, representing the transformed source code, and an optional array of `dependencies`.
|
||||||
|
|
||||||
|
The `markup` function receives the entire component source text, along with the component's `filename` if it was specified in the third argument.
|
||||||
|
|
||||||
|
> Preprocessor functions may additionally return a `map` object alongside `code` and `dependencies`, where `map` is a sourcemap representing the transformation. In current versions of Svelte it will be ignored, but future versions of Svelte may take account of preprocessor sourcemaps.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const svelte = require('svelte/compiler');
|
||||||
|
|
||||||
|
const { code } = svelte.preprocess(source, {
|
||||||
|
markup: ({ content, filename }) => {
|
||||||
|
return {
|
||||||
|
code: content.replace(/foo/g, 'bar')
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
filename: 'App.svelte'
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
The `script` and `style` functions receive the contents of `<script>` and `<style>` elements respectively. In addition to `filename`, they get an object of the element's attributes.
|
||||||
|
|
||||||
|
If a `dependencies` array is returned, it will be included in the result object. This is used by packages like [rollup-plugin-svelte](https://github.com/rollup/rollup-plugin-svelte) to watch additional files for changes, in the case where your `<style>` tag has an `@import` (for example).
|
||||||
|
|
||||||
|
```js
|
||||||
|
const svelte = require('svelte/compiler');
|
||||||
|
const sass = require('node-sass');
|
||||||
|
|
||||||
|
const { code, dependencies } = svelte.preprocess(source, {
|
||||||
|
style: ({ content, attributes, filename }) => {
|
||||||
|
// only process <style lang="sass">
|
||||||
|
if (attributes.lang !== 'sass') return;
|
||||||
|
|
||||||
|
const { css, stats } = await new Promise((resolve, reject) => sass.render({
|
||||||
|
file: filename,
|
||||||
|
data: content,
|
||||||
|
includePaths: [
|
||||||
|
dirname(filename),
|
||||||
|
],
|
||||||
|
}), (err, result) => {
|
||||||
|
if (err) reject(err);
|
||||||
|
else resolve(result);
|
||||||
|
}));
|
||||||
|
|
||||||
|
return {
|
||||||
|
code: css.toString(),
|
||||||
|
dependencies: stats.includedFiles
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
filename: 'App.svelte'
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Multiple preprocessors can be used together. The output of the first becomes the input to the second. `markup` functions run first, then `script` and `style`.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const svelte = require('svelte/compiler');
|
||||||
|
|
||||||
|
const { code } = svelte.preprocess(source, [
|
||||||
|
{
|
||||||
|
markup: () => {
|
||||||
|
console.log('this runs first');
|
||||||
|
},
|
||||||
|
script: () => {
|
||||||
|
console.log('this runs third');
|
||||||
|
},
|
||||||
|
style: () => {
|
||||||
|
console.log('this runs fifth');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
markup: () => {
|
||||||
|
console.log('this runs second');
|
||||||
|
},
|
||||||
|
script: () => {
|
||||||
|
console.log('this runs fourth');
|
||||||
|
},
|
||||||
|
style: () => {
|
||||||
|
console.log('this runs sixth');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
], {
|
||||||
|
filename: 'App.svelte'
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### svelte.VERSION
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
The current version, as set in package.json.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const svelte = require('svelte/compiler');
|
||||||
|
console.log(`running svelte version ${svelte.VERSION}`);
|
||||||
|
```
|
@ -1,7 +0,0 @@
|
|||||||
---
|
|
||||||
title: Important note
|
|
||||||
---
|
|
||||||
|
|
||||||
### Read the RFCs
|
|
||||||
|
|
||||||
Much of the documentation below is out of date! For more accurate and current information on how Svelte 3 works in the meantime, check out the RFCS on [reactive assignments](https://github.com/sveltejs/rfcs/blob/master/text/0001-reactive-assignments.md), [reactive stores](https://github.com/sveltejs/rfcs/blob/master/text/0002-reactive-stores.md) and [reactive declarations](https://github.com/sveltejs/rfcs/blob/master/text/0003-reactive-declarations.md).
|
|
@ -1,7 +0,0 @@
|
|||||||
<svelte:head>
|
|
||||||
<title>About</title>
|
|
||||||
</svelte:head>
|
|
||||||
|
|
||||||
<h1>About this site</h1>
|
|
||||||
|
|
||||||
<p>This is the 'about' page. There's not much here.</p>
|
|
@ -1,6 +1,6 @@
|
|||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { extract_frontmatter, langs } from '../../../utils/markdown.js';
|
import { extract_frontmatter, langs } from '../../utils/markdown.js';
|
||||||
import marked from 'marked';
|
import marked from 'marked';
|
||||||
import PrismJS from 'prismjs';
|
import PrismJS from 'prismjs';
|
||||||
import 'prismjs/components/prism-bash';
|
import 'prismjs/components/prism-bash';
|
@ -1,22 +0,0 @@
|
|||||||
import { demos } from '../_sections.js';
|
|
||||||
|
|
||||||
export function get(req, res) {
|
|
||||||
const { hash } = req.params;
|
|
||||||
|
|
||||||
if (!demos.has(hash)) {
|
|
||||||
res.writeHead(404, {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
});
|
|
||||||
|
|
||||||
res.end(JSON.stringify({
|
|
||||||
error: 'not found'
|
|
||||||
}));
|
|
||||||
} else {
|
|
||||||
const json = demos.get(hash);
|
|
||||||
res.writeHead(200, {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
});
|
|
||||||
|
|
||||||
res.end(json);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +1,10 @@
|
|||||||
/* generated by Svelte vX.Y.Z */
|
/* generated by Svelte vX.Y.Z */
|
||||||
import { create_ssr_component } from "svelte/internal";
|
import { create_ssr_component } from "svelte/internal";
|
||||||
|
|
||||||
const SvelteComponent = create_ssr_component(($$result, $$props, $$bindings, $$slots) => {
|
const Component = create_ssr_component(($$result, $$props, $$bindings, $$slots) => {
|
||||||
return `<div>content</div>
|
return `<div>content</div>
|
||||||
<!-- comment -->
|
<!-- comment -->
|
||||||
<div>more content</div>`;
|
<div>more content</div>`;
|
||||||
});
|
});
|
||||||
|
|
||||||
export default SvelteComponent;
|
export default Component;
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue