Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangfengming committed Oct 26, 2023
1 parent cd9929a commit 31f8f64
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 13 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Build and Publish

on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install dependencies
run: npm install

- name: Convert Markdown to HTML
run: npm run md2html

- name: Generate static site
env:
NOJS: 1
run: npm run build:ssg

- name: Publish dist folder
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: dist
6 changes: 3 additions & 3 deletions docs/en/ssr.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export default defineConfig({

Now, run `node ssr-dev-server.js` in the command line to start the HTTP service for the development environment and visit `http://localhost:5173` to see the effect.

We can observe the existence of a [FOUC (Flash of Unstyled Content)](https://en.wikipedia.org/wiki/Flash_of_unstyled_content) issue. In production mode, for projects that use Tailwind CSS, this can be resolved by setting the Vite configuration option `build.cssCodeSplit` to `true`. If your CSS is too large and needs to be loaded on demand, you can read the Vite compiled [ssr-manifest.json](https://vitejs.dev/guide/ssr.html#generating-preload-directives) file, and then insert the CSS files required for the current page into the HTML during server-side rendering. A specific implementation can be referred to in the [svelte-pilot-template](https://github.com/jiangfengming/svelte-pilot-template) project.
We can observe the existence of a [FOUC (Flash of Unstyled Content)](https://en.wikipedia.org/wiki/Flash_of_unstyled_content) issue. In production mode, for projects that use Tailwind CSS, this can be resolved by setting the Vite configuration option `build.cssCodeSplit` to `true`. If your CSS is too large and needs to be loaded on demand, you can read the Vite compiled [ssr-manifest.json](https://vitejs.dev/guide/ssr.html#generating-preload-directives) file, and then insert the CSS files required for the current page into the HTML during server-side rendering. A specific implementation can be referred to in the [svelte-pilot-template](https://github.com/svelte-pilot/svelte-pilot-template) project.

## Server Entry Point

Expand Down Expand Up @@ -268,7 +268,7 @@ The `load` function is called during server-side rendering, and the returned dat
The `load` function accepts three parameters:
- `props`: The `props` object of the view component.
- `route`: The current [route object](router#route).
- `context`: A custom context object. Passed as the second parameter when calling [router.handleServer()](router#routerhandleserver). You can store information like `headers`, `cookies`, etc., of the current request in the `context` object and also set the response’s `statusCode`, `statusMessage`, `headers`, etc. The specific implementation can be referred to in the [svelte-pilot-template](https://github.com/jiangfengming/svelte-pilot-template) project, details of which are not reiterated here.
- `context`: A custom context object. Passed as the second parameter when calling [router.handleServer()](router#routerhandleserver). You can store information like `headers`, `cookies`, etc., of the current request in the `context` object and also set the response’s `statusCode`, `statusMessage`, `headers`, etc. The specific implementation can be referred to in the [svelte-pilot-template](https://github.com/svelte-pilot/svelte-pilot-template) project, details of which are not reiterated here.

### Client-Side Calling the load Function

Expand Down Expand Up @@ -314,4 +314,4 @@ load.callOnClient = true
load.cacheKey = ['id']
```

By this point, you should have a basic understanding of implementing server-side rendering using Svelte Pilot. If you need to deploy on a serverless platform or generate a static website (Static-Site Generation), it can be achieved with minor modifications. You can directly use or refer to the [svelte-pilot-template](https://github.com/jiangfengming/svelte-pilot-template) project.
By this point, you should have a basic understanding of implementing server-side rendering using Svelte Pilot. If you need to deploy on a serverless platform or generate a static website (Static-Site Generation), it can be achieved with minor modifications. You can directly use or refer to the [svelte-pilot-template](https://github.com/svelte-pilot/svelte-pilot-template) project.
6 changes: 3 additions & 3 deletions docs/en/template.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Template

A template based on the [Svelte Pilot](https://github.com/jiangfengming/svelte-pilot) routing library, offering server-side rendering (SSR) and other rich features.
A template based on the [Svelte Pilot](https://github.com/svelte-pilot/svelte-pilot) routing library, offering server-side rendering (SSR) and other rich features.

## Core Features
- **Multiple Deployment Modes**: Supports SSR (Server-Side Rendering), SSG (Static Site Generation), SPA (Single Page Application), and serverless functions.
- **Powerful Routing and Layout System**: Supported by [Svelte Pilot](https://github.com/jiangfengming/svelte-pilot).
- **Powerful Routing and Layout System**: Supported by [Svelte Pilot](https://github.com/svelte-pilot/svelte-pilot).
- **Integrated with TypeScript**: For type safety and robust coding.
- **Integrated with PostCSS and Tailwind CSS**: Ready to use without configuration.
- **Convenient Image Import**: Use the `<img src="./img.png">` tag directly without manually writing `import`.
- **Enhanced CSS Isolation**: Through [svelte-preprocess-css-hash](https://github.com/jiangfengming/svelte-preprocess-css-hash), `<Child class="--child">` becomes `<Child class="--child-HaShEd">`.

## Quick Preview
Experience the editable demo on the [StackBlitz Online IDE](https://stackblitz.com/~/github.com/jiangfengming/svelte-pilot-template?startScript=dev:ssr).
Experience the editable demo on the [StackBlitz Online IDE](https://stackblitz.com/~/github.com/svelte-pilot/svelte-pilot-template?startScript=dev:ssr).

## Create a Project

Expand Down
6 changes: 3 additions & 3 deletions docs/zh-CN/ssr.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export default defineConfig({

现在,我们可以在命令行中运行 `node ssr-dev-server.js` 来启动开发环境 HTTP 服务,然后访问 `http://localhost:5173` 来查看效果。

我们能看到存在 [FOUC](https://en.wikipedia.org/wiki/Flash_of_unstyled_content) 问题。在生产模式下,对于使用了 Tailwind CSS 的项目,我们可以通过设置 Vite 的配置项 `build.cssCodeSplit``true` 来解决。如果你的 CSS 太大,需要按需加载,可以通过读取 Vite 编译生成的 [ssr-manifest.json](https://vitejs.dev/guide/ssr.html#generating-preload-directives) 文件,然后在服务端渲染时把当前页面所需的 CSS 文件插入到 HTML 中。具体实现可以参考 [svelte-pilot-template](https://github.com/jiangfengming/svelte-pilot-template) 项目。
我们能看到存在 [FOUC](https://en.wikipedia.org/wiki/Flash_of_unstyled_content) 问题。在生产模式下,对于使用了 Tailwind CSS 的项目,我们可以通过设置 Vite 的配置项 `build.cssCodeSplit``true` 来解决。如果你的 CSS 太大,需要按需加载,可以通过读取 Vite 编译生成的 [ssr-manifest.json](https://vitejs.dev/guide/ssr.html#generating-preload-directives) 文件,然后在服务端渲染时把当前页面所需的 CSS 文件插入到 HTML 中。具体实现可以参考 [svelte-pilot-template](https://github.com/svelte-pilot/svelte-pilot-template) 项目。

## 服务端入口

Expand Down Expand Up @@ -268,7 +268,7 @@ npm i sirv
`load` 函数接受三个参数:
- `props`:视图组件的 `props` 对象。
- `route`:当前[路由对象](router#route)
- `context`: 自定义上下文对象。在调用 [router.handleServer()](router#routerhandleserver) 时作为第二个参数传入。你可以通过 `context` 对象储存当前请求的 `headers``cookies` 等信息,还可以实现设置响应的 `statusCode``statusMessage``headers` 等功能。具体实现可以参考 [svelte-pilot-template](https://github.com/jiangfengming/svelte-pilot-template) 项目,这里不再赘述。
- `context`: 自定义上下文对象。在调用 [router.handleServer()](router#routerhandleserver) 时作为第二个参数传入。你可以通过 `context` 对象储存当前请求的 `headers``cookies` 等信息,还可以实现设置响应的 `statusCode``statusMessage``headers` 等功能。具体实现可以参考 [svelte-pilot-template](https://github.com/svelte-pilot/svelte-pilot-template) 项目,这里不再赘述。

### 客户端调用 load 函数
当我们在客户端使用 HTML5 History API 进行路由跳转时,视图组件的 `load` 函数默认不会被调用,这会导致客户端渲染时缺少数据。我们有三种解决办法:
Expand Down Expand Up @@ -313,4 +313,4 @@ load.callOnClient = true
load.cacheKey = ['id']
```

看到这里,相信你已经了解了使用 Svelte Pilot 实现服务端渲染的基本流程。如果你需要在无服务(Serverless)平台上部署,或者生成静态网站(Static-Site Generation),只需稍加改造就可以实现。您可以直接使用或参考 [svelte-pilot-template](https://github.com/jiangfengming/svelte-pilot-template) 项目。
看到这里,相信你已经了解了使用 Svelte Pilot 实现服务端渲染的基本流程。如果你需要在无服务(Serverless)平台上部署,或者生成静态网站(Static-Site Generation),只需稍加改造就可以实现。您可以直接使用或参考 [svelte-pilot-template](https://github.com/svelte-pilot/svelte-pilot-template) 项目。
6 changes: 3 additions & 3 deletions docs/zh-CN/template.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# 模板

基于 [Svelte Pilot](https://github.com/jiangfengming/svelte-pilot) 路由库的模板,提供了服务端渲染(SSR)和其他丰富功能。
基于 [Svelte Pilot](https://github.com/svelte-pilot/svelte-pilot) 路由库的模板,提供了服务端渲染(SSR)和其他丰富功能。

## 核心特性
- **多种部署模式**:无论是 SSR(服务端渲染)、SSG(静态站点生成)、SPA(单页应用程序),还是无服务器函数,应有尽有。
- **强大的路由和布局系统**:由 [Svelte Pilot](https://github.com/jiangfengming/svelte-pilot) 提供支持。
- **强大的路由和布局系统**:由 [Svelte Pilot](https://github.com/svelte-pilot/svelte-pilot) 提供支持。
- **集成 TypeScript**:以实现类型安全和稳健的编码。
- **集成 PostCSS 和 Tailwind CSS**:无需配置开箱即用。
- **方便的图片导入**`<img src="./img.png">` 标签直接使用图片,无需手写 `import`
- **增强 CSS 隔离**:通过 [svelte-preprocess-css-hash](https://github.com/jiangfengming/svelte-preprocess-css-hash)`<Child class="--child">` 变为 `<Child class="--child-HaShEd">`

## 快速预览
[StackBlitz 在线 IDE](https://stackblitz.com/~/github.com/jiangfengming/svelte-pilot-template?startScript=dev:ssr) 上体验可编辑的演示。
[StackBlitz 在线 IDE](https://stackblitz.com/~/github.com/svelte-pilot/svelte-pilot-template?startScript=dev:ssr) 上体验可编辑的演示。

## 创建项目

Expand Down
2 changes: 1 addition & 1 deletion src/views/Layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@

<div class="mt-5 text-slate-600">
<a
href="https://github.com/jiangfengming/svelte-pilot-docs/edit/main/docs/{lang}/{slug}.md"
href="https://github.com/svelte-pilot/svelte-pilot.github.io/edit/main/docs/{lang}/{slug}.md"
>{messages.edit_this_page}</a
>
</div>
Expand Down

0 comments on commit 31f8f64

Please sign in to comment.