move things around

pull/1/head
Evan You 4 years ago
parent 9069e4673b
commit 2bf64da748

@ -1,2 +1,4 @@
#!/usr/bin/env node
require('../dist')
require('../dist').createServer().listen(3000, () => {
console.log('listening at http://localhost:3000')
})

@ -0,0 +1,2 @@
<div id="app"></div>
<script type="module" src="/@app/index.js"></script>

@ -0,0 +1,23 @@
import { createApp, ref, provide, h } from 'vue'
import { Layout } from '/@theme/index.js'
const app = createApp({
setup() {
const path = ref(window.location.pathname)
// window.addEventListener('click', e => {
// if (e.target.tagName === 'A') {
// e.preventDefault()
// if (e.target.href && e.target.href.indexOf(location.host)) {
// history.pushState(null, '', e.target.href)
// }
// }
// })
provide('vitepress:path', path)
return () => h(Layout)
}
})
app.mount('#app')

@ -0,0 +1 @@
export * from './server'

@ -0,0 +1,52 @@
import path from 'path'
import { createServer as createViteServer, cachedRead, Plugin } from 'vite'
const debug = require('debug')('vitepress')
// built ts files are placed into /dist
const resolveAppFile = (file: string) =>
path.join(__dirname, '../lib/app', file)
// TODO detect user configured theme
const resolveThemeFile = (file: string) =>
path.join(__dirname, '../lib/theme-default', file)
const VitePressPlugin: Plugin = ({ root, app }) => {
app.use(async (ctx, next) => {
// detect and serve vitepress app files
if (ctx.path.startsWith('/@app')) {
const file = ctx.path.replace(/^\/@app\/?/, '')
ctx.type = path.extname(file)
ctx.body = await cachedRead(resolveAppFile(file))
debug(`serving app file: ${ctx.url}`)
return next()
}
if (ctx.path.startsWith('/@theme')) {
const file = ctx.path.replace(/^\/@theme\/?/, '')
ctx.type = path.extname(file)
ctx.body = await cachedRead(resolveThemeFile(file))
debug(`serving theme file: ${ctx.url}`)
return next()
}
if (ctx.path.endsWith('.md')) {
debug(`serving .md: ${ctx.path}`)
}
await next()
// serve our index.html after vite history fallback
if (ctx.url === '/index.html') {
ctx.type = 'text/html'
ctx.body = await cachedRead(resolveAppFile('index-dev.html'))
}
})
}
export function createServer() {
return createViteServer({
plugins: [VitePressPlugin]
})
}

@ -0,0 +1,3 @@
<template>
hello world
</template>

@ -0,0 +1,3 @@
import Layout from './Layout.vue'
export { Layout }

@ -16,7 +16,9 @@
],
"author": "Evan You",
"license": "MIT",
"dependencies": {},
"dependencies": {
"debug": "^4.1.1"
},
"devDependencies": {
"typescript": "^3.8.3"
}

@ -1,25 +0,0 @@
import { createServer, Plugin } from 'vite'
import path from 'path'
import { promises as fs } from 'fs'
const indexTemplate = fs.readFile(path.join(__dirname, '../theme/index.html'))
const VitePressPlugin: Plugin = ({ root, app }) => {
app.use(async (ctx, next) => {
// redirect request to index.html
if (ctx.path === '/index.html') {
ctx.body = await indexTemplate
return
}
return next()
})
app.use(async (ctx, next) => {})
}
createServer({
plugins: [VitePressPlugin]
}).listen(3000, () => {
console.log('listening on http://localhost:3000')
})

@ -17,5 +17,5 @@
"removeComments": false,
"preserveSymlinks": true
},
"include": ["src"]
"include": ["lib"]
}

@ -2,6 +2,18 @@
# yarn lockfile v1
debug@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.1.1.tgz#3b72260255109c6b589cee050f1d516139664791"
integrity sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==
dependencies:
ms "^2.1.1"
ms@^2.1.1:
version "2.1.2"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==
typescript@^3.8.3:
version "3.8.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.8.3.tgz#409eb8544ea0335711205869ec458ab109ee1061"

Loading…
Cancel
Save