feat(demo): build a static editor preview for GitHub Pages
This commit is contained in:
1 parent
12d13327a6
commit
4645d3d11c
10 files changed
+57
-5
No files matched your search
@@ -1,6 +1,7 @@
|
|||||||
.git
|
.git
|
||||||
web/node_modules
|
web/node_modules
|
||||||
web/dist
|
web/dist
|
||||||
|
web/dist-demo
|
||||||
CONTEXT.md
|
CONTEXT.md
|
||||||
docs
|
docs
|
||||||
.dev-data
|
.dev-data
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ docs/*
|
|||||||
# Frontend
|
# Frontend
|
||||||
node_modules/
|
node_modules/
|
||||||
web/dist/
|
web/dist/
|
||||||
|
web/dist-demo/
|
||||||
|
|
||||||
# Local development data
|
# Local development data
|
||||||
.dev-data/
|
.dev-data/
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
|
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
|
||||||
<title>RawMark Editor Demo</title>
|
<title>RawMark Editor Demo</title>
|
||||||
|
<link rel="icon" href="/icon.svg" type="image/svg+xml" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "vue-tsc --noEmit && vite build",
|
"build": "vue-tsc --noEmit && vite build",
|
||||||
|
"build:demo": "vue-tsc --noEmit && vite build --mode demo --base /RawMark/ --outDir dist-demo",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"lint": "eslint --fix",
|
"lint": "eslint --fix",
|
||||||
"test": "vitest run",
|
"test": "vitest run",
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"demo_notice": "Editor preview only. Changes are not saved; refreshing restores the sample.",
|
||||||
"retry_b8784c": "Retry",
|
"retry_b8784c": "Retry",
|
||||||
"fonts_could_not_be_loaded_42a574": "Fonts could not be loaded. Check your connection and refresh the page.",
|
"fonts_could_not_be_loaded_42a574": "Fonts could not be loaded. Check your connection and refresh the page.",
|
||||||
"refresh_page_9366e1": "Refresh page",
|
"refresh_page_9366e1": "Refresh page",
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"demo_notice": "仅供编辑器预览。修改不会保存,刷新后恢复示例。",
|
||||||
"retry_b8784c": "重试",
|
"retry_b8784c": "重试",
|
||||||
"fonts_could_not_be_loaded_42a574": "字体加载失败,请检查网络后刷新页面。",
|
"fonts_could_not_be_loaded_42a574": "字体加载失败,请检查网络后刷新页面。",
|
||||||
"refresh_page_9366e1": "刷新页面",
|
"refresh_page_9366e1": "刷新页面",
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 8px 16px;
|
||||||
|
padding: 12px 20px;
|
||||||
|
border-bottom: 1px solid var(--rm-divider);
|
||||||
|
font-size: var(--rm-ui-font-size);
|
||||||
|
}
|
||||||
|
|
||||||
|
header span {
|
||||||
|
flex: 1;
|
||||||
|
color: var(--rm-text-muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
header a {
|
||||||
|
color: var(--rm-accent);
|
||||||
|
}
|
||||||
|
|
||||||
|
#app {
|
||||||
|
max-width: 960px;
|
||||||
|
margin-inline: auto;
|
||||||
|
}
|
||||||
@@ -1,14 +1,26 @@
|
|||||||
import { watchFontLoading } from '@@/appearance/font-loading'
|
import { watchFontLoading } from '@@/appearance/font-loading'
|
||||||
|
import { t } from '@@/i18n/runtime'
|
||||||
// Unauthenticated editor demo for automated performance and interaction tests.
|
// Unauthenticated editor demo for automated performance and interaction tests.
|
||||||
import { createEditorState, createEditorView } from '../editor'
|
import { createEditorState, createEditorView } from '../editor'
|
||||||
import sample from './sample.md?raw'
|
import sample from './sample.md?raw'
|
||||||
import '@/i18n'
|
import '@/i18n'
|
||||||
import '@@/appearance/base.css'
|
import '@@/appearance/base.css'
|
||||||
|
import './demo.css'
|
||||||
|
|
||||||
// ?repeat=N repeats the sample N times for large-document performance testing.
|
// ?repeat=N repeats the sample N times for large-document performance testing.
|
||||||
const repeat = Number(new URLSearchParams(location.search).get('repeat') ?? 1)
|
const repeat = Number(new URLSearchParams(location.search).get('repeat') ?? 1)
|
||||||
const doc = Array.from({ length: Math.max(1, repeat) }).fill(sample).join('\n')
|
const doc = Array.from({ length: Math.max(1, repeat) }).fill(sample).join('\n')
|
||||||
|
|
||||||
watchFontLoading()
|
watchFontLoading()
|
||||||
|
const header = document.createElement('header')
|
||||||
|
const title = document.createElement('strong')
|
||||||
|
title.textContent = `RawMark ${__RAWMARK_RELEASE__}`
|
||||||
|
const notice = document.createElement('span')
|
||||||
|
notice.textContent = t('common.demo_notice')
|
||||||
|
const github = document.createElement('a')
|
||||||
|
github.href = 'https://github.com/eezd/RawMark'
|
||||||
|
github.textContent = 'GitHub'
|
||||||
|
header.append(title, notice, github)
|
||||||
|
document.body.prepend(header)
|
||||||
const view = createEditorView(document.getElementById('app')!, createEditorState({ doc }))
|
const view = createEditorView(document.getElementById('app')!, createEditorState({ doc }))
|
||||||
;(window as unknown as { rawmarkView: typeof view }).rawmarkView = view
|
;(window as unknown as { rawmarkView: typeof view }).rawmarkView = view
|
||||||
@@ -52,7 +52,7 @@ func main() {
|
|||||||
|
|
||||||
## Images
|
## Images
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## Tables
|
## Tables
|
||||||
|
|
||||||
|
|||||||
+11
-4
@@ -10,7 +10,7 @@ import { defineConfig } from 'vitest/config'
|
|||||||
|
|
||||||
const releaseVersion = readFileSync(new URL('../VERSION', import.meta.url), 'utf8').trim()
|
const releaseVersion = readFileSync(new URL('../VERSION', import.meta.url), 'utf8').trim()
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig(({ mode }) => ({
|
||||||
define: { __RAWMARK_RELEASE__: JSON.stringify(releaseVersion) },
|
define: { __RAWMARK_RELEASE__: JSON.stringify(releaseVersion) },
|
||||||
resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)), '@@': fileURLToPath(new URL('./src/common', import.meta.url)) } },
|
resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)), '@@': fileURLToPath(new URL('./src/common', import.meta.url)) } },
|
||||||
plugins: [
|
plugins: [
|
||||||
@@ -18,9 +18,16 @@ export default defineConfig({
|
|||||||
UnoCSS(),
|
UnoCSS(),
|
||||||
AutoImport({ imports: ['vue', 'vue-router', 'pinia'], dts: 'types/auto/auto-imports.d.ts' }),
|
AutoImport({ imports: ['vue', 'vue-router', 'pinia'], dts: 'types/auto/auto-imports.d.ts' }),
|
||||||
Components({ dts: 'types/auto/components.d.ts', resolvers: [ElementPlusResolver({ importStyle: false })] }),
|
Components({ dts: 'types/auto/components.d.ts', resolvers: [ElementPlusResolver({ importStyle: false })] }),
|
||||||
|
{
|
||||||
|
name: 'rawmark-demo-entry',
|
||||||
|
apply: (_config, env) => env.command === 'build' && env.mode === 'demo',
|
||||||
|
generateBundle() {
|
||||||
|
this.emitFile({ type: 'asset', fileName: 'index.html', source: '<!doctype html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="refresh" content="0;url=./demo.html"><title>RawMark Demo</title></head><body><a href="./demo.html">Open RawMark Demo</a></body></html>' })
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'rawmark-pwa',
|
name: 'rawmark-pwa',
|
||||||
apply: 'build',
|
apply: (_config, env) => env.command === 'build' && env.mode !== 'demo',
|
||||||
enforce: 'post',
|
enforce: 'post',
|
||||||
generateBundle(_options, bundle) {
|
generateBundle(_options, bundle) {
|
||||||
// Count only optional application fonts; fonts.css excludes Maple and KaTeX.
|
// Count only optional application fonts; fonts.css excludes Maple and KaTeX.
|
||||||
@@ -58,7 +65,7 @@ export default defineConfig({
|
|||||||
build: {
|
build: {
|
||||||
rolldownOptions: {
|
rolldownOptions: {
|
||||||
// demo.html is an unauthenticated editor demo for automated performance/interaction tests.
|
// demo.html is an unauthenticated editor demo for automated performance/interaction tests.
|
||||||
input: { index: 'index.html', demo: 'demo.html' },
|
input: mode === 'demo' ? 'demo.html' : { index: 'index.html', demo: 'demo.html' },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
worker: { format: 'es' },
|
worker: { format: 'es' },
|
||||||
@@ -67,4 +74,4 @@ export default defineConfig({
|
|||||||
proxy: { '/api': { target: `http://127.0.0.1:${process.env.API_PORT ?? 8080}`, ws: true } },
|
proxy: { '/api': { target: `http://127.0.0.1:${process.env.API_PORT ?? 8080}`, ws: true } },
|
||||||
},
|
},
|
||||||
test: { environment: 'node', setupFiles: ['./src/i18n.ts'] },
|
test: { environment: 'node', setupFiles: ['./src/i18n.ts'] },
|
||||||
})
|
}))
|
||||||
Reference in new issue
Block a user