Refactoring complet : contenu livre, config unique, routes, admin et light mode
- Source unique : supprime app/data/librodrome.config.yml, renomme site/ en bookplayer.config.yml - Morceaux : renommés avec slugs lisibles, fichiers audio renommés, inversion ch2↔ch3 corrigée - Chapitres : 11 fichiers .md réécrits avec le vrai contenu du livre (synthèse fidèle du PDF) - Routes : /lire → /modele-eco, /ecouter → /en-musique, redirections 301 - Admin chapitres : champs structurés (titre, description, temps lecture), compteur mots - Éditeur markdown : mode split, plein écran, support Tab, meilleur rendu aperçu - Admin morceaux : drag & drop, ajout/suppression, gestion playlist - Light mode : palettes printemps/été plus saturées et contrastées, teintes primary - Raccourcis clavier player : espace, flèches gauche/droite - Paroles : toggle supprimé, toujours visibles et scrollables - Nouvelles pages : autonomie, evenement Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
16
server/api/admin/chapters/[slug].delete.ts
Normal file
16
server/api/admin/chapters/[slug].delete.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { unlink } from 'node:fs/promises'
|
||||
import { join } from 'node:path'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const slug = getRouterParam(event, 'slug')
|
||||
|
||||
if (!slug || !/^[a-z0-9-]+$/.test(slug)) {
|
||||
throw createError({ statusCode: 400, statusMessage: 'Invalid slug' })
|
||||
}
|
||||
|
||||
const filePath = join(process.cwd(), 'content', 'book', `${slug}.md`)
|
||||
|
||||
await unlink(filePath)
|
||||
|
||||
return { ok: true }
|
||||
})
|
||||
29
server/api/admin/chapters/index.post.ts
Normal file
29
server/api/admin/chapters/index.post.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { writeFile } from 'node:fs/promises'
|
||||
import { join } from 'node:path'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody<{ slug: string; title: string; order: number }>(event)
|
||||
|
||||
if (!body?.slug || !body?.title) {
|
||||
throw createError({ statusCode: 400, statusMessage: 'Missing slug or title' })
|
||||
}
|
||||
|
||||
if (!/^[a-z0-9-]+$/.test(body.slug)) {
|
||||
throw createError({ statusCode: 400, statusMessage: 'Invalid slug format' })
|
||||
}
|
||||
|
||||
const filePath = join(process.cwd(), 'content', 'book', `${body.slug}.md`)
|
||||
|
||||
const content = `---
|
||||
title: "${body.title}"
|
||||
description: ""
|
||||
order: ${body.order}
|
||||
readingTime: "5 min"
|
||||
---
|
||||
|
||||
`
|
||||
|
||||
await writeFile(filePath, content, 'utf-8')
|
||||
|
||||
return { ok: true, slug: body.slug }
|
||||
})
|
||||
29
server/api/admin/chapters/index.put.ts
Normal file
29
server/api/admin/chapters/index.put.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { readFile, writeFile } from 'node:fs/promises'
|
||||
import { join } from 'node:path'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody<{ chapters: { slug: string; order: number }[] }>(event)
|
||||
|
||||
if (!body?.chapters || !Array.isArray(body.chapters)) {
|
||||
throw createError({ statusCode: 400, statusMessage: 'Missing chapters array' })
|
||||
}
|
||||
|
||||
const bookDir = join(process.cwd(), 'content', 'book')
|
||||
|
||||
await Promise.all(
|
||||
body.chapters.map(async ({ slug, order }) => {
|
||||
const filePath = join(bookDir, `${slug}.md`)
|
||||
const raw = await readFile(filePath, 'utf-8')
|
||||
|
||||
// Replace order in frontmatter
|
||||
const updated = raw.replace(
|
||||
/^(---\n[\s\S]*?)order:\s*\d+/,
|
||||
`$1order: ${order}`,
|
||||
)
|
||||
|
||||
await writeFile(filePath, updated, 'utf-8')
|
||||
}),
|
||||
)
|
||||
|
||||
return { ok: true }
|
||||
})
|
||||
@@ -1,5 +1,5 @@
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody(event)
|
||||
await writeYaml('librodrome.config.yml', body)
|
||||
await writeYaml('bookplayer.config.yml', body)
|
||||
return { ok: true }
|
||||
})
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export default defineEventHandler(async () => {
|
||||
return await readYaml('librodrome.config.yml')
|
||||
return await readYaml('bookplayer.config.yml')
|
||||
})
|
||||
|
||||
13
server/middleware/redirects.ts
Normal file
13
server/middleware/redirects.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export default defineEventHandler((event) => {
|
||||
const path = getRequestURL(event).pathname
|
||||
|
||||
if (path.startsWith('/lire')) {
|
||||
const rest = path.slice(5) // remove '/lire'
|
||||
return sendRedirect(event, `/modele-eco${rest || '/'}`, 301)
|
||||
}
|
||||
|
||||
if (path.startsWith('/ecouter')) {
|
||||
const rest = path.slice(8) // remove '/ecouter'
|
||||
return sendRedirect(event, `/en-musique${rest || '/'}`, 301)
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user