Add Makefile, package.json, and initial configuration for VitePress and Slidev integration
- Introduced a Makefile for streamlined commands related to building, running, and managing presentations. - Created package.json to define project metadata, dependencies, and scripts for development and testing. - Added .gitignore entries to exclude build artifacts and temporary files from version control. - Included playwright.config.mjs for end-to-end testing setup with Playwright. - Added README.md for project documentation, outlining setup instructions and development guidelines.
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* Sert dist-portal + chaque dist-<slug> sous /slides/<slug>/ (tests E2E, prod locale).
|
||||
* Comme le plugin Vite en dev : racine du deck → 302 vers /slides/<slug>/1 ; routes Slidev (/1, /2…) via SPA (sirv single).
|
||||
*/
|
||||
import http from 'node:http'
|
||||
import path from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import sirv from 'sirv'
|
||||
import { listPresentationSlugs } from './list-slugs.mjs'
|
||||
|
||||
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
|
||||
const port = Number(process.env.PREVIEW_PORT || 4174)
|
||||
|
||||
const portalStatic = sirv(path.join(root, 'dist-portal'), { etag: true })
|
||||
const slideSirv = new Map()
|
||||
|
||||
function getSirv(slug) {
|
||||
if (!slideSirv.has(slug)) {
|
||||
slideSirv.set(
|
||||
slug,
|
||||
sirv(path.join(root, `dist-${slug}`), {
|
||||
etag: true,
|
||||
single: 'index.html',
|
||||
}),
|
||||
)
|
||||
}
|
||||
return slideSirv.get(slug)
|
||||
}
|
||||
|
||||
const server = http.createServer((req, res) => {
|
||||
const u = new URL(req.url || '/', 'http://127.0.0.1')
|
||||
const pathname = u.pathname
|
||||
const m = pathname.match(/^\/slides\/([^/]+)(.*)$/)
|
||||
if (m) {
|
||||
const slug = m[1]
|
||||
const rest = m[2] || '/'
|
||||
const slugs = new Set(listPresentationSlugs(root))
|
||||
if (!slugs.has(slug)) {
|
||||
res.statusCode = 404
|
||||
res.end('not found')
|
||||
return
|
||||
}
|
||||
const atDeckRoot = rest === '/' || rest === ''
|
||||
if (atDeckRoot && (req.method === 'GET' || req.method === 'HEAD')) {
|
||||
res.statusCode = 302
|
||||
res.setHeader('Location', `/slides/${slug}/1${u.search || ''}`)
|
||||
res.end()
|
||||
return
|
||||
}
|
||||
const orig = req.url
|
||||
req.url = rest + (u.search || '')
|
||||
getSirv(slug)(req, res, () => {
|
||||
req.url = orig
|
||||
res.statusCode = 404
|
||||
res.end()
|
||||
})
|
||||
return
|
||||
}
|
||||
portalStatic(req, res, () => {
|
||||
res.statusCode = 404
|
||||
res.end('not found')
|
||||
})
|
||||
})
|
||||
|
||||
server.listen(port, '127.0.0.1', () => {
|
||||
console.log(`[static-preview] http://127.0.0.1:${port}/`)
|
||||
})
|
||||
Reference in New Issue
Block a user