Skip to content

Commit 883bc6f

Browse files
authored
feat: sync docs (by copying them) (#69)
This implements a different approach to syncing the docs. Rather than creating a toolchain that requires git sync or similar on build and keeps things transient, this approach implements a script that is invoked separately (and can be part of a github action for example) that mostly copies the documentation from the target repositories over into the omnisite, while also invoking scripts for creating the generated reference docs. The result is saved to disk, which has a few advantages: - build is massively simpler: no dependencies on flaky git or other remote sources, as everything is already there - getting started is easier, no need to sync first, just checkout the repo and go. This is especially helpful if you're working on the site itself, not the content - translations will be easier: just don't invoke the sync script, instead modify the directories by hand. Keeping up to date with the source will also be easier because you can git-diff changes to docs Closes #20
1 parent 360f95f commit 883bc6f

File tree

103 files changed

+16579
-9416
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+16579
-9416
lines changed

apps/svelte.dev/.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@
66
/src/routes/_home/Supporters/contributors.js
77
/src/routes/_home/Supporters/donors.jpg
88
/src/routes/_home/Supporters/donors.js
9-
/static/svelte-app.json
9+
/static/svelte-app.json
10+
11+
# git-repositories of synced docs go here
12+
/repos/

apps/svelte.dev/.prettierignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
_generated.md
1+
content/docs
22
scripts/create-tutorial-zip/common/.svelte-kit
33
land-110m.json
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
title: Introduction
3+
---
4+
5+
## Before we begin
6+
7+
> If you're new to Svelte or SvelteKit we recommend checking out the [interactive tutorial](https://learn.svelte.dev).
8+
>
9+
> If you get stuck, reach out for help in the [Discord chatroom](https://svelte.dev/chat).
10+
11+
## What is SvelteKit?
12+
13+
SvelteKit is a framework for rapidly developing robust, performant web applications using [Svelte](https://svelte.dev/). If you're coming from React, SvelteKit is similar to Next. If you're coming from Vue, SvelteKit is similar to Nuxt.
14+
15+
To learn more about the kinds of applications you can build with SvelteKit, see the [FAQ](/docs/faq#what-can-i-make-with-sveltekit).
16+
17+
## What is Svelte?
18+
19+
In short, Svelte is a way of writing user interface components — like a navigation bar, comment section, or contact form — that users see and interact with in their browsers. The Svelte compiler converts your components to JavaScript that can be run to render the HTML for the page and to CSS that styles the page. You don't need to know Svelte to understand the rest of this guide, but it will help. If you'd like to learn more, check out [the Svelte tutorial](https://svelte.dev/tutorial).
20+
21+
## SvelteKit vs Svelte
22+
23+
Svelte renders UI components. You can compose these components and render an entire page with just Svelte, but you need more than just Svelte to write an entire app.
24+
25+
SvelteKit helps you build web apps while following modern best practices and providing solutions to common development challenges. It offers everything from basic functionalities — like a [router](glossary#routing) that updates your UI when a link is clicked — to more advanced capabilities. Its extensive list of features includes [build optimizations](https://vitejs.dev/guide/features.html#build-optimizations) to load only the minimal required code; [offline support](service-workers); [preloading](link-options#data-sveltekit-preload-data) pages before user navigation; [configurable rendering](page-options) to handle different parts of your app on the server via [SSR](glossary#ssr), in the browser through [client-side rendering](glossary#csr), or at build-time with [prerendering](glossary#prerendering); [image optimization](images); and much more. Building an app with all the modern best practices is fiendishly complicated, but SvelteKit does all the boring stuff for you so that you can get on with the creative part.
26+
27+
It reflects changes to your code in the browser instantly to provide a lightning-fast and feature-rich development experience by leveraging [Vite](https://vitejs.dev/) with a [Svelte plugin](https://github.com/sveltejs/vite-plugin-svelte) to do [Hot Module Replacement (HMR)](https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/config.md#hot).
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
title: Creating a project
3+
---
4+
5+
The easiest way to start building a SvelteKit app is to run `npm create`:
6+
7+
```bash
8+
npm create svelte@latest my-app
9+
cd my-app
10+
npm install
11+
npm run dev
12+
```
13+
14+
The first command will scaffold a new project in the `my-app` directory asking you if you'd like to set up some basic tooling such as TypeScript. See [integrations](./integrations) for pointers on setting up additional tooling. The subsequent commands will then install its dependencies and start a server on [localhost:5173](http://localhost:5173).
15+
16+
There are two basic concepts:
17+
18+
- Each page of your app is a [Svelte](https://svelte.dev) component
19+
- You create pages by adding files to the `src/routes` directory of your project. These will be server-rendered so that a user's first visit to your app is as fast as possible, then a client-side app takes over
20+
21+
Try editing the files to get a feel for how everything works.
22+
23+
## Editor setup
24+
25+
We recommend using [Visual Studio Code (aka VS Code)](https://code.visualstudio.com/download) with [the Svelte extension](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode), but [support also exists for numerous other editors](https://sveltesociety.dev/resources#editor-support).
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
---
2+
title: Project structure
3+
---
4+
5+
A typical SvelteKit project looks like this:
6+
7+
```bash
8+
my-project/
9+
├ src/
10+
│ ├ lib/
11+
│ │ ├ server/
12+
│ │ │ └ [your server-only lib files]
13+
│ │ └ [your lib files]
14+
│ ├ params/
15+
│ │ └ [your param matchers]
16+
│ ├ routes/
17+
│ │ └ [your routes]
18+
│ ├ app.html
19+
│ ├ error.html
20+
│ ├ hooks.client.js
21+
│ ├ hooks.server.js
22+
│ └ service-worker.js
23+
├ static/
24+
│ └ [your static assets]
25+
├ tests/
26+
│ └ [your tests]
27+
├ package.json
28+
├ svelte.config.js
29+
├ tsconfig.json
30+
└ vite.config.js
31+
```
32+
33+
You'll also find common files like `.gitignore` and `.npmrc` (and `.prettierrc` and `eslint.config.js` and so on, if you chose those options when running `npm create svelte@latest`).
34+
35+
## Project files
36+
37+
### src
38+
39+
The `src` directory contains the meat of your project. Everything except `src/routes` and `src/app.html` is optional.
40+
41+
- `lib` contains your library code (utilities and components), which can be imported via the [`$lib`](modules#$lib) alias, or packaged up for distribution using [`svelte-package`](packaging)
42+
- `server` contains your server-only library code. It can be imported by using the [`$lib/server`](server-only-modules) alias. SvelteKit will prevent you from importing these in client code.
43+
- `params` contains any [param matchers](advanced-routing#matching) your app needs
44+
- `routes` contains the [routes](routing) of your application. You can also colocate other components that are only used within a single route here
45+
- `app.html` is your page template — an HTML document containing the following placeholders:
46+
- `%sveltekit.head%``<link>` and `<script>` elements needed by the app, plus any `<svelte:head>` content
47+
- `%sveltekit.body%` — the markup for a rendered page. This should live inside a `<div>` or other element, rather than directly inside `<body>`, to prevent bugs caused by browser extensions injecting elements that are then destroyed by the hydration process. SvelteKit will warn you in development if this is not the case
48+
- `%sveltekit.assets%` — either [`paths.assets`](configuration#paths), if specified, or a relative path to [`paths.base`](configuration#paths)
49+
- `%sveltekit.nonce%` — a [CSP](configuration#csp) nonce for manually included links and scripts, if used
50+
- `%sveltekit.env.[NAME]%` - this will be replaced at render time with the `[NAME]` environment variable, which must begin with the [`publicPrefix`](configuration#env) (usually `PUBLIC_`). It will fallback to `''` if not matched.
51+
- `error.html` is the page that is rendered when everything else fails. It can contain the following placeholders:
52+
- `%sveltekit.status%` — the HTTP status
53+
- `%sveltekit.error.message%` — the error message
54+
- `hooks.client.js` contains your client [hooks](hooks)
55+
- `hooks.server.js` contains your server [hooks](hooks)
56+
- `service-worker.js` contains your [service worker](service-workers)
57+
58+
(Whether the project contains `.js` or `.ts` files depends on whether you opt to use TypeScript when you create your project. You can switch between JavaScript and TypeScript in the documentation using the toggle at the bottom of this page.)
59+
60+
If you added [Vitest](https://vitest.dev) when you set up your project, your unit tests will live in the `src` directory with a `.test.js` extension.
61+
62+
### static
63+
64+
Any static assets that should be served as-is, like `robots.txt` or `favicon.png`, go in here.
65+
66+
### tests
67+
68+
If you added [Playwright](https://playwright.dev/) for browser testing when you set up your project, the tests will live in this directory.
69+
70+
### package.json
71+
72+
Your `package.json` file must include `@sveltejs/kit`, `svelte` and `vite` as `devDependencies`.
73+
74+
When you create a project with `npm create svelte@latest`, you'll also notice that `package.json` includes `"type": "module"`. This means that `.js` files are interpreted as native JavaScript modules with `import` and `export` keywords. Legacy CommonJS files need a `.cjs` file extension.
75+
76+
### svelte.config.js
77+
78+
This file contains your Svelte and SvelteKit [configuration](configuration).
79+
80+
### tsconfig.json
81+
82+
This file (or `jsconfig.json`, if you prefer type-checked `.js` files over `.ts` files) configures TypeScript, if you added typechecking during `npm create svelte@latest`. Since SvelteKit relies on certain configuration being set a specific way, it generates its own `.svelte-kit/tsconfig.json` file which your own config `extends`.
83+
84+
### vite.config.js
85+
86+
A SvelteKit project is really just a [Vite](https://vitejs.dev) project that uses the [`@sveltejs/kit/vite`](modules#sveltejs-kit-vite) plugin, along with any other [Vite configuration](https://vitejs.dev/config/).
87+
88+
## Other files
89+
90+
### .svelte-kit
91+
92+
As you develop and build your project, SvelteKit will generate files in a `.svelte-kit` directory (configurable as [`outDir`](configuration#outdir)). You can ignore its contents, and delete them at any time (they will be regenerated when you next `dev` or `build`).
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
---
2+
title: Web standards
3+
---
4+
5+
Throughout this documentation, you'll see references to the standard [Web APIs](https://developer.mozilla.org/en-US/docs/Web/API) that SvelteKit builds on top of. Rather than reinventing the wheel, we _use the platform_, which means your existing web development skills are applicable to SvelteKit. Conversely, time spent learning SvelteKit will help you be a better web developer elsewhere.
6+
7+
These APIs are available in all modern browsers and in many non-browser environments like Cloudflare Workers, Deno, and Vercel Functions. During development, and in [adapters](adapters) for Node-based environments (including AWS Lambda), they're made available via polyfills where necessary (for now, that is — Node is rapidly adding support for more web standards).
8+
9+
In particular, you'll get comfortable with the following:
10+
11+
## Fetch APIs
12+
13+
SvelteKit uses [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/fetch) for getting data from the network. It's available in [hooks](hooks) and [server routes](routing#server) as well as in the browser.
14+
15+
> A special version of `fetch` is available in [`load`](load) functions, [server hooks](hooks#server-hooks) and [API routes](routing#server) for invoking endpoints directly during server-side rendering, without making an HTTP call, while preserving credentials. (To make credentialled fetches in server-side code outside `load`, you must explicitly pass `cookie` and/or `authorization` headers.) It also allows you to make relative requests, whereas server-side `fetch` normally requires a fully qualified URL.
16+
17+
Besides `fetch` itself, the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) includes the following interfaces:
18+
19+
### Request
20+
21+
An instance of [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request) is accessible in [hooks](hooks) and [server routes](routing#server) as `event.request`. It contains useful methods like `request.json()` and `request.formData()` for getting data that was posted to an endpoint.
22+
23+
### Response
24+
25+
An instance of [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) is returned from `await fetch(...)` and handlers in `+server.js` files. Fundamentally, a SvelteKit app is a machine for turning a `Request` into a `Response`.
26+
27+
### Headers
28+
29+
The [`Headers`](https://developer.mozilla.org/en-US/docs/Web/API/Headers) interface allows you to read incoming `request.headers` and set outgoing `response.headers`. For example, you can get the `request.headers` as shown below, and use the [`json` convenience function](modules#sveltejs-kit-json) to send modified `response.headers`:
30+
31+
```js
32+
// @errors: 2461
33+
/// file: src/routes/what-is-my-user-agent/+server.js
34+
import { json } from '@sveltejs/kit';
35+
36+
/** @type {import('./$types').RequestHandler} */
37+
export function GET({ request }) {
38+
// log all headers
39+
console.log(...request.headers);
40+
41+
// create a JSON Response using a header we received
42+
return json({
43+
// retrieve a specific header
44+
userAgent: request.headers.get('user-agent')
45+
}, {
46+
// set a header on the response
47+
headers: { 'x-custom-header': 'potato' }
48+
});
49+
}
50+
```
51+
52+
## FormData
53+
54+
When dealing with HTML native form submissions you'll be working with [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData) objects.
55+
56+
```js
57+
// @errors: 2461
58+
/// file: src/routes/hello/+server.js
59+
import { json } from '@sveltejs/kit';
60+
61+
/** @type {import('./$types').RequestHandler} */
62+
export async function POST(event) {
63+
const body = await event.request.formData();
64+
65+
// log all fields
66+
console.log([...body]);
67+
68+
return json({
69+
// get a specific field's value
70+
name: body.get('name') ?? 'world'
71+
});
72+
}
73+
```
74+
75+
## Stream APIs
76+
77+
Most of the time, your endpoints will return complete data, as in the `userAgent` example above. Sometimes, you may need to return a response that's too large to fit in memory in one go, or is delivered in chunks, and for this the platform provides [streams](https://developer.mozilla.org/en-US/docs/Web/API/Streams_API) — [ReadableStream](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream), [WritableStream](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream) and [TransformStream](https://developer.mozilla.org/en-US/docs/Web/API/TransformStream).
78+
79+
## URL APIs
80+
81+
URLs are represented by the [`URL`](https://developer.mozilla.org/en-US/docs/Web/API/URL) interface, which includes useful properties like `origin` and `pathname` (and, in the browser, `hash`). This interface shows up in various places — `event.url` in [hooks](hooks) and [server routes](routing#server), [`$page.url`](modules#$app-stores) in [pages](routing#page), `from` and `to` in [`beforeNavigate` and `afterNavigate`](modules#$app-navigation) and so on.
82+
83+
### URLSearchParams
84+
85+
Wherever you encounter a URL, you can access query parameters via `url.searchParams`, which is an instance of [`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams):
86+
87+
```js
88+
// @filename: ambient.d.ts
89+
declare global {
90+
const url: URL;
91+
}
92+
93+
export {};
94+
95+
// @filename: index.js
96+
// ---cut---
97+
const foo = url.searchParams.get('foo');
98+
```
99+
100+
## Web Crypto
101+
102+
The [Web Crypto API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API) is made available via the `crypto` global. It's used internally for [Content Security Policy](configuration#csp) headers, but you can also use it for things like generating UUIDs:
103+
104+
```js
105+
const uuid = crypto.randomUUID();
106+
```
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
title: Getting started
3+
---

0 commit comments

Comments
 (0)