Autor-Seiten: /authors/<slug>/ (rundes Bild, Name, Bio, zentriert) + Byline-Link
- layouts/authors/single.html rendert die Autor-Seite zentriert - Byline in single.html + index.html verlinkt den Autornamen zu /authors/<urlize name>/ (nur wenn die Seite existiert) - CMS-Profil-Speichern schreibt content/authors/<slug>.md (aus Name/Bio/Avatar) + data/authors.json und baut public neu → Seite & Links sofort live - Autor-Seiten aus dem Inhalts-Editor ausgeblendet (über „Profil" verwaltet) - custom.css: .author-page / -photo / -name / -bio + Byline-Link-Stil Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -66,6 +66,8 @@ export async function listEntries() {
|
||||
const items = [];
|
||||
for (const full of files) {
|
||||
const rel = path.relative(CONTENT, full).split(path.sep).join('/');
|
||||
// Autor-Seiten werden über „Profil" verwaltet, nicht im Inhalts-Editor.
|
||||
if (rel === 'authors' || rel.startsWith('authors/')) continue;
|
||||
let data = {};
|
||||
try { data = matter(await readFile(full, 'utf8')).data || {}; } catch {}
|
||||
items.push({
|
||||
|
||||
@@ -1,15 +1,23 @@
|
||||
import { Hono } from 'hono';
|
||||
import { readFile, writeFile, mkdir } from 'node:fs/promises';
|
||||
import { readFile, writeFile, mkdir, stat } from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import matter from 'gray-matter';
|
||||
import { hugoBuild } from '../hugo.js';
|
||||
|
||||
// Profile als Hugo-Data-Datei: data/authors.json (Map E-Mail → Profil).
|
||||
// So kann das Theme die Autor:innen via site.Data.authors rendern.
|
||||
// Profile als Hugo-Data-Datei (data/authors.json) + öffentliche Autor-Seite
|
||||
// (content/authors/<slug>.md), gerendert von layouts/authors/single.html.
|
||||
const SITE_DIR = process.env.SITE_DIR || '/site';
|
||||
const FILE = path.join(SITE_DIR, 'data', 'authors.json');
|
||||
const AUTHORS_DIR = path.join(SITE_DIR, 'content', 'authors');
|
||||
|
||||
async function readAll() {
|
||||
try { return JSON.parse(await readFile(FILE, 'utf8')); } catch { return {}; }
|
||||
}
|
||||
// Muss zu Hugos `urlize` passen (Byline-Link).
|
||||
function slugify(s) {
|
||||
return String(s || '').toLowerCase().trim().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
|
||||
}
|
||||
async function exists(p) { try { await stat(p); return true; } catch { return false; } }
|
||||
|
||||
const profile = new Hono();
|
||||
|
||||
@@ -22,11 +30,27 @@ profile.get('/', async (c) => {
|
||||
profile.put('/', async (c) => {
|
||||
const email = c.get('user')?.email || 'default';
|
||||
const { name, bio, avatar } = await c.req.json();
|
||||
const slug = slugify(name);
|
||||
|
||||
const all = await readAll();
|
||||
all[email] = { name: name || '', bio: bio || '', avatar: avatar || '' };
|
||||
all[email] = { name: name || '', bio: bio || '', avatar: avatar || '', slug };
|
||||
await mkdir(path.dirname(FILE), { recursive: true });
|
||||
await writeFile(FILE, JSON.stringify(all, null, 2) + '\n', 'utf8');
|
||||
return c.json({ ok: true });
|
||||
|
||||
// Öffentliche Autor-Seite schreiben (nur mit Name).
|
||||
if (slug) {
|
||||
await mkdir(AUTHORS_DIR, { recursive: true });
|
||||
const idx = path.join(AUTHORS_DIR, '_index.md');
|
||||
if (!(await exists(idx))) {
|
||||
await writeFile(idx, matter.stringify('', { title: 'Autor:innen' }), 'utf8');
|
||||
}
|
||||
const page = matter.stringify(bio || '', { title: name, avatar: avatar || '' });
|
||||
await writeFile(path.join(AUTHORS_DIR, `${slug}.md`), page, 'utf8');
|
||||
// Live bauen, damit die Seite + Byline-Links sofort funktionieren.
|
||||
await hugoBuild({ dest: 'public', drafts: false }).catch(() => {});
|
||||
}
|
||||
|
||||
return c.json({ ok: true, slug });
|
||||
});
|
||||
|
||||
export default profile;
|
||||
|
||||
Reference in New Issue
Block a user