First commit
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
# dev.sh runtime artifacts
|
||||
.logs/
|
||||
.pids/
|
||||
152
AGENTS.md
Normal file
152
AGENTS.md
Normal file
@@ -0,0 +1,152 @@
|
||||
# Mathew — a wiki for mathematics
|
||||
|
||||
A collaborative wiki of math concepts. Articles are written in Markdown with LaTeX
|
||||
(KaTeX) and stored in MongoDB behind an Express API; a Nuxt 4 app renders and edits them.
|
||||
|
||||
```
|
||||
mathew/
|
||||
├── dev.sh # starts/stops both dev servers together
|
||||
├── backend/ Express 5 + Mongoose API (port 5000)
|
||||
└── frontend/ Nuxt 4 / Vue 3 wiki UI (port 3000)
|
||||
```
|
||||
|
||||
## Running the project
|
||||
|
||||
Requires MongoDB on `localhost:27017` (database `mathew`).
|
||||
|
||||
```bash
|
||||
./dev.sh # both dev servers in foreground (Ctrl+C stops both)
|
||||
./dev.sh start|stop|restart|status
|
||||
./dev.sh logs [all|backend|frontend]
|
||||
```
|
||||
|
||||
Or per-service: `npm run dev` inside `backend/` or `frontend/`
|
||||
(backend uses `node --watch`; backend has no build step).
|
||||
|
||||
Seed sample articles: `npm run seed` in `backend/`.
|
||||
|
||||
Environment: `backend/.env` (`PORT=5000`, `MONGO_URI=mongodb://127.0.0.1:27017/mathew`,
|
||||
`JWT_SECRET` — signs session tokens, `AUTH_TOKEN_TTL` — how long one lasts, default `7d`;
|
||||
see `.env.example`). Without `JWT_SECRET` the API warns and uses an insecure dev key.
|
||||
Frontend API URL comes from `NUXT_PUBLIC_API_BASE`
|
||||
(default `http://localhost:5000`, read via `runtimeConfig.public.apiBase`).
|
||||
|
||||
There is **no test suite, linter, or typecheck script** configured — don't invent commands.
|
||||
|
||||
## Backend (`backend/`)
|
||||
|
||||
Plain JavaScript, ESM (`"type": "module"`, `.js` files with relative `.js` import specifiers).
|
||||
|
||||
- `src/index.js` — app setup: CORS, JSON body, `/health`, routers, 404 handler, central
|
||||
error handler (Mongoose `ValidationError`/`CastError` → 400), graceful shutdown. After
|
||||
the connection it calls `User.ensureAnAdmin()` so somebody can always open the dashboard.
|
||||
- `src/config/db.js` — `connectDB` / `disconnectDB`.
|
||||
- `src/models/` — Mongoose schemas with `timestamps: true`. `Article` (slug, title,
|
||||
summary, content, tags + text index), `Item` (simple demo resource),
|
||||
`User` (username + `passwordHash`, `select: false`; `setPassword`/`checkPassword`
|
||||
via bcrypt, `toPublic()` for responses, and `credentialProblem()` as the single
|
||||
place account rules are checked). The profile picture lives on `User.avatar` as a
|
||||
small data URL — no file storage. `User.role` is `'admin'` or `'member'`
|
||||
(`ROLES`); `User.hasNone()` and `User.ensureAnAdmin()` cover who gets the
|
||||
former — see the roles gotcha below.
|
||||
- `src/routes/` — one Express `Router` per resource, mounted in `index.js`.
|
||||
- `src/routes/auth.js` — `POST /api/auth/register` (creates the account and returns
|
||||
its session; the wiki's **first** account is created as an admin),
|
||||
`POST /api/auth/login`, `GET /api/auth/me` (who a token belongs to).
|
||||
Login answers the same way to a wrong name and a wrong password. Account updates,
|
||||
all behind `requireAuth`: `PUT /api/auth/me` (rename), `PUT /api/auth/password`
|
||||
(needs the current one), `PUT /api/auth/avatar` (data URL, `""` clears).
|
||||
- `src/routes/admin.js` — mounted at `/api/admin`, everything behind
|
||||
`requireAuth, requireAdmin`: `GET /api/admin/users` (every account, newest
|
||||
first, with `createdAt`), `PUT /api/admin/users/:id/role` (`role` is `'admin'`
|
||||
or `'member'`; an admin's own role is the one they cannot change), and
|
||||
`DELETE /api/admin/users/:id` (closes an account for good — never their own,
|
||||
by the same rule; the articles it wrote stay, since articles name no author).
|
||||
- `src/middleware/auth.js` — `signToken(user)`, `requireAuth`, which reads
|
||||
`Authorization: Bearer <token>` and sets `req.user = { id, username }`; anything
|
||||
else is answered with 401 `{ message }`. `requireAdmin` runs after it and reads
|
||||
the role off the **account** (403 `{ message }` for a member), so removing the
|
||||
role works the next time the dashboard is asked for.
|
||||
- `src/seed.js` — sample articles.
|
||||
|
||||
Conventions to follow:
|
||||
|
||||
- Every handler is `async` with `try { ... } catch (err) { next(err); }`; the central
|
||||
error handler in `index.js` formats responses (`{ message }` everywhere).
|
||||
- Articles are addressed by **slug**, not by Mongo id (`/api/articles/slug/:slug`).
|
||||
`slugify()` / `uniqueSlug()` (in `routes/articles.js`) generate uniquified slugs
|
||||
(`-2`, `-3`, ... suffixes); POST requires `title`, PUT re-slugs when the title changes.
|
||||
- The list endpoint (`GET /api/articles`) selects `-content` (no body) and supports
|
||||
`?q=` (regex search on title/summary/tags) and `?tag=`.
|
||||
- Reads are public; the writes (`POST /api/articles`, `PUT`/`DELETE` by slug) run
|
||||
through `requireAuth`.
|
||||
|
||||
## Frontend (`frontend/`)
|
||||
|
||||
Nuxt 4 (srcDir `app/`, TypeScript, Vue 3 `<script setup>` SFCs). No UI framework —
|
||||
hand-rolled SCSS (devDep `sass`) in `app/assets/css/`: `main.scss` `@use`s one
|
||||
partial per section (`_tokens`, `_layout`, `_editor`, `_book`, …); shared shapes
|
||||
(popups, dropdowns, segmented controls, avatars) are mixins in `_mixins.scss`, and
|
||||
the accent themes generate from a map in `_tokens.scss`. Colours stay CSS custom
|
||||
properties so themes swap at runtime via `data-theme`/`data-accent` attributes
|
||||
(set pre-paint by an inline script in `nuxt.config.ts`).
|
||||
|
||||
- `app/pages/` — `/` (search), `/wiki/[slug]` (article + TOC), `/wiki/[slug]/edit`, `/new`,
|
||||
`/admin` (the dashboard: every account and its role, plus the buttons that hand the
|
||||
role on or take it back — an admin alone sees anything but a refusal here).
|
||||
The two editor routes wrap their form in `AuthGate`, so it shows only with a session.
|
||||
- `app/components/` — PascalCase SFCs (header, editor, MarkdownView, TocNav, etc.).
|
||||
`AuthGate.vue` is the editor's stand-in for a signed-out visitor; `AuthModal.vue`
|
||||
is the popup that signs them in; `ProfileModal.vue` is the account popup the
|
||||
sidebar's account row opens (picture, username, password, sign out). `ConfirmModal.vue`
|
||||
is the yes/no popup any destructive step asks through (the editor's discard, the
|
||||
dashboard's delete). All popups (teleported overlays, closed by esc/backdrop/
|
||||
navigation like the other popups — opening one calls `hide()` on the others,
|
||||
they never stack). A row of actions folds into a ⋮ menu built on the shared
|
||||
`.kebab*` styles: `ArticleActionsMenu.vue` on an article's title row,
|
||||
`AccountActionsMenu.vue` on a row of the dashboard (the role and the account).
|
||||
- `app/composables/` — `useTopics` (topics = distinct tags computed client-side from the
|
||||
full article list, shared via `useState`), `useRecentlyViewed` (localStorage),
|
||||
`useAuth` (the session: token in the `mathew-session` cookie so the server sees it
|
||||
too, `signIn`/`signUp`/`signOut`, `authHeaders()` for write calls, `restoreSession()`
|
||||
asking `/auth/me` who a stored token belongs to, plus `updateUsername`/
|
||||
`changePassword`/`setAvatar` for the profile popup, and `isAdmin` — whether the
|
||||
account holds the admin role, which is what the sidebar's Admin link and the
|
||||
dashboard are drawn from), `useSignInPopup` (open state of
|
||||
that popup, shaped like `useSettings`/`useSearch`), `useProfileMenu` (same, for the
|
||||
profile popup), `useArticleActionsMenu` (same, for an article's ⋮ menu), and
|
||||
`useAccountActionsMenu` (same, for a dashboard row's ⋮ — it holds the **id** of
|
||||
the row that is open, so one row's menu is open at a time rather than a
|
||||
boolean per row).
|
||||
- `app/plugins/auth.ts` — runs `restoreSession()` once at startup on server and client,
|
||||
so the sidebar's account row and the editor's gate are right in the first render.
|
||||
- `app/utils/markdown.ts` — the single render pipeline: `markdown-it` (**html: false**,
|
||||
raw HTML is escaped) + `markdown-it-texmath` + KaTeX (`$...$` inline, `$$...$$` display,
|
||||
macros `\R \N \Z \Q \C`) + highlight.js, sanitized with DOMPurify. It also builds the
|
||||
TOC. Render all article Markdown through this, not ad-hoc renderers.
|
||||
- API calls use `$fetch` against `${useRuntimeConfig().public.apiBase}/api`.
|
||||
|
||||
## Gotchas
|
||||
|
||||
- Reading is open; **writing takes an account**. `POST /api/articles` and `PUT`/`DELETE`
|
||||
by slug need `Authorization: Bearer <token>` from `/api/auth/login` or
|
||||
`/api/auth/register`. The frontend keeps that token in the `mathew-session` cookie
|
||||
(readable by the app, sent as a header — it is not an httpOnly session cookie), so a
|
||||
set `JWT_SECRET` matters in production; anyone with the dev key can mint a session.
|
||||
- A 401 from a write means the held session is dead; the editor keeps the draft and
|
||||
opens the sign-in popup over it rather than signing out and unmounting the form.
|
||||
- Anyone may register, and an account cannot edit another's article (articles store
|
||||
no author). Roles are the one difference between accounts: `role` is `'admin'` or
|
||||
`'member'`. **The first account ever registered is the admin** — and on a wiki
|
||||
whose accounts all predate the role, `User.ensureAnAdmin()` gives it to the oldest
|
||||
one at startup. Admins promote and demote from `/admin`; nobody may change their
|
||||
own role, so there is always at least one admin left to open the page. The same
|
||||
menu deletes an account — through `ConfirmModal`, and never the admin's own, for
|
||||
the same reason. Articles outlive the account that wrote them.
|
||||
- Profile pictures are stored as data URLs on the account (the browser shrinks them
|
||||
to a 256px square before upload); `express.json` allows 1.5 MB bodies so one fits
|
||||
a request. A 401 from a profile update means the session died — the popup signs
|
||||
out and opens the sign-in popup over it.
|
||||
- Changing an article's title can change its slug; old URLs 404 (no redirects).
|
||||
- Frontend dev server may fall back to port 3001 if 3000 is taken.
|
||||
- `frontend/types/markdown-it-texmath.d.ts` provides types for the untyped texmath package.
|
||||
4
backend/.env.example
Normal file
4
backend/.env.example
Normal file
@@ -0,0 +1,4 @@
|
||||
PORT=5000
|
||||
MONGO_URI=mongodb://127.0.0.1:27017/mathew
|
||||
JWT_SECRET=change-me-64-hex-chars
|
||||
AUTH_TOKEN_TTL=7d
|
||||
2
backend/.gitignore
vendored
Normal file
2
backend/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
node_modules/
|
||||
.env
|
||||
1279
backend/package-lock.json
generated
Normal file
1279
backend/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
21
backend/package.json
Normal file
21
backend/package.json
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "mathew-backend",
|
||||
"version": "1.0.0",
|
||||
"description": "Minimal Node backend using Express and Mongoose",
|
||||
"main": "src/index.js",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"start": "node src/index.js",
|
||||
"dev": "node --watch src/index.js",
|
||||
"seed": "node src/seed.js"
|
||||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"bcryptjs": "^3.0.3",
|
||||
"cors": "^2.8.6",
|
||||
"dotenv": "^17.4.2",
|
||||
"express": "^5.2.1",
|
||||
"jsonwebtoken": "^9.0.3",
|
||||
"mongoose": "^8.24.4"
|
||||
}
|
||||
}
|
||||
15
backend/src/config/auth.js
Normal file
15
backend/src/config/auth.js
Normal file
@@ -0,0 +1,15 @@
|
||||
import "dotenv/config";
|
||||
|
||||
// Secret that signs session tokens. Anyone holding it can mint tokens that
|
||||
// pass for accounts, so it belongs in the environment and never in the repo.
|
||||
// The fallback keeps `./dev.sh` working out of the box — loudly.
|
||||
const DEV_SECRET = "mathew-development-secret-set-JWT_SECRET-in-backend-env";
|
||||
|
||||
export const JWT_SECRET = process.env.JWT_SECRET || DEV_SECRET;
|
||||
|
||||
// How long a sign-in lasts. Long enough to survive a weekend of writing.
|
||||
export const TOKEN_TTL = process.env.AUTH_TOKEN_TTL || "7d";
|
||||
|
||||
if (!process.env.JWT_SECRET) {
|
||||
console.warn("[auth] JWT_SECRET is not set — using an insecure development key.");
|
||||
}
|
||||
11
backend/src/config/db.js
Normal file
11
backend/src/config/db.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import mongoose from "mongoose";
|
||||
|
||||
export async function connectDB() {
|
||||
const uri = process.env.MONGO_URI || "mongodb://127.0.0.1:27017/mathew";
|
||||
await mongoose.connect(uri);
|
||||
console.log(`MongoDB connected: ${mongoose.connection.host}`);
|
||||
}
|
||||
|
||||
export async function disconnectDB() {
|
||||
await mongoose.disconnect();
|
||||
}
|
||||
72
backend/src/index.js
Normal file
72
backend/src/index.js
Normal file
@@ -0,0 +1,72 @@
|
||||
import "dotenv/config";
|
||||
import express from "express";
|
||||
import cors from "cors";
|
||||
import mongoose from "mongoose";
|
||||
import { connectDB, disconnectDB } from "./config/db.js";
|
||||
import itemsRouter from "./routes/items.js";
|
||||
import articlesRouter from "./routes/articles.js";
|
||||
import authRouter from "./routes/auth.js";
|
||||
import adminRouter from "./routes/admin.js";
|
||||
import User from "./models/User.js";
|
||||
|
||||
const app = express();
|
||||
|
||||
// Middleware
|
||||
app.use(cors());
|
||||
// Room for a profile picture sent as a data URL (see PUT /api/auth/avatar).
|
||||
app.use(express.json({ limit: "1.5mb" }));
|
||||
|
||||
// Routes
|
||||
app.get("/health", (req, res) => {
|
||||
res.json({
|
||||
status: "ok",
|
||||
mongo: mongoose.connection.readyState === 1 ? "connected" : "disconnected",
|
||||
});
|
||||
});
|
||||
|
||||
app.use("/api/items", itemsRouter);
|
||||
app.use("/api/auth", authRouter);
|
||||
app.use("/api/articles", articlesRouter);
|
||||
app.use("/api/admin", adminRouter);
|
||||
|
||||
// 404 handler
|
||||
app.use((req, res) => {
|
||||
res.status(404).json({ message: "Not found" });
|
||||
});
|
||||
|
||||
// Central error handler
|
||||
app.use((err, req, res, next) => {
|
||||
if (err.name === "ValidationError") {
|
||||
return res.status(400).json({ message: err.message });
|
||||
}
|
||||
if (err.name === "CastError") {
|
||||
return res.status(400).json({ message: "Invalid id format" });
|
||||
}
|
||||
console.error(err);
|
||||
res.status(err.status || 500).json({ message: err.message || "Server error" });
|
||||
});
|
||||
|
||||
// Start server after connecting to MongoDB
|
||||
const port = process.env.PORT || 5000;
|
||||
|
||||
try {
|
||||
await connectDB();
|
||||
// Accounts opened before there were roles: the oldest of them gets one, so
|
||||
// somebody can always open the dashboard and pass the role to anyone else.
|
||||
const promoted = await User.ensureAnAdmin();
|
||||
if (promoted) console.log(`Admin role given to the oldest account: ${promoted.username}`);
|
||||
app.listen(port, () => {
|
||||
console.log(`Server listening on http://localhost:${port}`);
|
||||
});
|
||||
} catch (err) {
|
||||
console.error("Failed to start server:", err.message);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Graceful shutdown
|
||||
for (const signal of ["SIGINT", "SIGTERM"]) {
|
||||
process.on(signal, async () => {
|
||||
await disconnectDB();
|
||||
process.exit(0);
|
||||
});
|
||||
}
|
||||
60
backend/src/middleware/auth.js
Normal file
60
backend/src/middleware/auth.js
Normal file
@@ -0,0 +1,60 @@
|
||||
import jwt from "jsonwebtoken";
|
||||
import { JWT_SECRET, TOKEN_TTL } from "../config/auth.js";
|
||||
import User from "../models/User.js";
|
||||
|
||||
/** Issues a session token for an account. */
|
||||
export function signToken(user) {
|
||||
return jwt.sign(
|
||||
{ sub: user._id.toString(), username: user.username },
|
||||
JWT_SECRET,
|
||||
{ expiresIn: TOKEN_TTL }
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the `Authorization: Bearer <token>` header and puts the account on
|
||||
* `req.user`; anything else and the request stops here with 401. The message
|
||||
* bodies are what the frontend keys off: a 401 means the session it holds is
|
||||
* no good, so it drops it and asks the person to sign in again.
|
||||
*/
|
||||
export function requireAuth(req, res, next) {
|
||||
const [scheme, token] = String(req.headers.authorization || "").split(" ");
|
||||
|
||||
if (scheme !== "Bearer" || !token) {
|
||||
return res.status(401).json({ message: "Please sign in to do that." });
|
||||
}
|
||||
|
||||
let session;
|
||||
try {
|
||||
session = jwt.verify(token, JWT_SECRET);
|
||||
} catch {
|
||||
return res
|
||||
.status(401)
|
||||
.json({ message: "That session has expired — please sign in again." });
|
||||
}
|
||||
|
||||
req.user = { id: session.sub, username: session.username };
|
||||
next();
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs after `requireAuth` and lets an admin through alone. The role is read
|
||||
* from the account rather than trusted from the token, so taking it away works
|
||||
* the next time the dashboard is asked for — a token issued while the account
|
||||
* was an admin is no good once it is not.
|
||||
*/
|
||||
export async function requireAdmin(req, res, next) {
|
||||
try {
|
||||
const account = await User.findById(req.user.id);
|
||||
if (!account) {
|
||||
return res.status(401).json({ message: "No such account any more." });
|
||||
}
|
||||
if (account.role !== "admin") {
|
||||
return res.status(403).json({ message: "This is for administrators." });
|
||||
}
|
||||
req.user.role = account.role;
|
||||
next();
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
}
|
||||
52
backend/src/models/Article.js
Normal file
52
backend/src/models/Article.js
Normal file
@@ -0,0 +1,52 @@
|
||||
import mongoose from "mongoose";
|
||||
|
||||
const articleSchema = new mongoose.Schema(
|
||||
{
|
||||
slug: {
|
||||
type: String,
|
||||
required: [true, "Slug is required"],
|
||||
unique: true,
|
||||
lowercase: true,
|
||||
trim: true,
|
||||
index: true,
|
||||
},
|
||||
title: {
|
||||
type: String,
|
||||
required: [true, "Title is required"],
|
||||
trim: true,
|
||||
},
|
||||
content: {
|
||||
type: String,
|
||||
default: "",
|
||||
},
|
||||
tags: {
|
||||
type: [String],
|
||||
default: [],
|
||||
},
|
||||
// Language this version of the article is written in, as a lowercase
|
||||
// ISO 639-1 code ("en", "fr", "de", ...). Defaults to English.
|
||||
language: {
|
||||
type: String,
|
||||
default: "en",
|
||||
lowercase: true,
|
||||
trim: true,
|
||||
},
|
||||
// For a translation: the identity of the article it translates — the
|
||||
// canonical (original) version's slug. Null on the canonical document.
|
||||
baseSlug: {
|
||||
type: String,
|
||||
default: null,
|
||||
lowercase: true,
|
||||
trim: true,
|
||||
index: true,
|
||||
},
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
// Text index for search across title and tags
|
||||
articleSchema.index({ title: "text", tags: "text" });
|
||||
|
||||
const Article = mongoose.model("Article", articleSchema);
|
||||
|
||||
export default Article;
|
||||
21
backend/src/models/Item.js
Normal file
21
backend/src/models/Item.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import mongoose from "mongoose";
|
||||
|
||||
const itemSchema = new mongoose.Schema(
|
||||
{
|
||||
name: {
|
||||
type: String,
|
||||
required: [true, "Name is required"],
|
||||
trim: true,
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
default: "",
|
||||
trim: true,
|
||||
},
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
const Item = mongoose.model("Item", itemSchema);
|
||||
|
||||
export default Item;
|
||||
124
backend/src/models/User.js
Normal file
124
backend/src/models/User.js
Normal file
@@ -0,0 +1,124 @@
|
||||
import mongoose from "mongoose";
|
||||
import bcrypt from "bcryptjs";
|
||||
|
||||
export const ROLES = ["admin", "member"];
|
||||
|
||||
/* The interface languages the web app offers (mirrors its own catalogue); the
|
||||
account stores its owner's choice so the wiki speaks their language on every
|
||||
device. "" means no choice yet — the device's own language decides. */
|
||||
export const SUPPORTED_LOCALES = ["en", "es", "ca", "fr", "de"];
|
||||
|
||||
export const USERNAME_REGEX = /^[a-z0-9_.-]{3,30}$/;
|
||||
export const USERNAME_MESSAGE =
|
||||
"Username must be 3-30 characters: letters, numbers, dot, dash or underscore.";
|
||||
export const PASSWORD_MIN = 8;
|
||||
export const PASSWORD_MESSAGE = `Password must be at least ${PASSWORD_MIN} characters.`;
|
||||
|
||||
/**
|
||||
* The one place account rules are written down: both the schema and the routes
|
||||
* check through this, so they cannot drift apart. Returns a message, or null
|
||||
* when the pair is usable.
|
||||
*/
|
||||
export function credentialProblem({ username, password }) {
|
||||
if (!USERNAME_REGEX.test(username)) return USERNAME_MESSAGE;
|
||||
if (password.length < PASSWORD_MIN) return PASSWORD_MESSAGE;
|
||||
if (password.length > 200) return "Password is too long.";
|
||||
return null;
|
||||
}
|
||||
|
||||
const userSchema = new mongoose.Schema(
|
||||
{
|
||||
username: {
|
||||
type: String,
|
||||
required: [true, "Username is required"],
|
||||
unique: true,
|
||||
lowercase: true,
|
||||
trim: true,
|
||||
index: true,
|
||||
match: [USERNAME_REGEX, USERNAME_MESSAGE],
|
||||
},
|
||||
// Hashed on the way in and left out of queries by default: no route sends
|
||||
// a password, hashed or otherwise, back to a client.
|
||||
passwordHash: {
|
||||
type: String,
|
||||
required: true,
|
||||
select: false,
|
||||
},
|
||||
// Profile picture kept as a data URL (the frontend shrinks it before
|
||||
// sending), so the avatar travels in the user object itself and the API
|
||||
// needs no file storage of its own. "" means no picture: an initial shows.
|
||||
avatar: {
|
||||
type: String,
|
||||
default: "",
|
||||
},
|
||||
/* Two kinds of account. A member reads and writes like anyone else; an admin
|
||||
additionally opens the dashboard of accounts and hands the role on. It is
|
||||
stored on the account rather than carried in the session token, so taking
|
||||
it away takes effect the next time a page asks. */
|
||||
role: {
|
||||
type: String,
|
||||
enum: { values: ROLES, message: `Role is one of: ${ROLES.join(", ")}.` },
|
||||
default: "member",
|
||||
},
|
||||
locale: {
|
||||
type: String,
|
||||
enum: {
|
||||
values: ["", ...SUPPORTED_LOCALES],
|
||||
message: `Language is one of: ${SUPPORTED_LOCALES.join(", ")}.`,
|
||||
},
|
||||
default: "",
|
||||
lowercase: true,
|
||||
trim: true,
|
||||
},
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
/** Hashes the plain password into `passwordHash`. The plain one is never saved. */
|
||||
userSchema.methods.setPassword = async function setPassword(plain) {
|
||||
this.passwordHash = await bcrypt.hash(String(plain), 10);
|
||||
return this;
|
||||
};
|
||||
|
||||
/** Checks a plain password against the stored hash; needs that field selected. */
|
||||
userSchema.methods.checkPassword = function checkPassword(plain) {
|
||||
return bcrypt.compare(String(plain ?? ""), this.passwordHash);
|
||||
};
|
||||
|
||||
/** The shape the API returns for an account: never the hash. */
|
||||
userSchema.methods.toPublic = function toPublic() {
|
||||
return {
|
||||
id: this._id.toString(),
|
||||
username: this.username,
|
||||
avatar: this.avatar ?? "",
|
||||
// Accounts opened before the role existed answer as plain members.
|
||||
role: this.role === "admin" ? "admin" : "member",
|
||||
// "" until the person chooses one in the settings popup.
|
||||
locale: this.locale ?? "",
|
||||
};
|
||||
};
|
||||
|
||||
/* Someone has to be able to hand the admin role on, so an empty wiki gives it
|
||||
to the first account it ever registers (see routes/auth.js). */
|
||||
userSchema.statics.hasNone = async function hasNone() {
|
||||
return (await this.estimatedDocumentCount()) === 0;
|
||||
};
|
||||
|
||||
/* And a wiki whose accounts all predate the role gives it to the oldest of
|
||||
them, once, at startup — otherwise the dashboard would have nobody who can
|
||||
open it. Answers the account it promoted, or null when there was nothing to
|
||||
do: an admin already about, or no account at all yet. */
|
||||
userSchema.statics.ensureAnAdmin = async function ensureAnAdmin() {
|
||||
if (await this.exists({ role: "admin" })) return null;
|
||||
|
||||
const oldest = await this.findOne().sort({ createdAt: 1 });
|
||||
if (!oldest) return null;
|
||||
|
||||
oldest.role = "admin";
|
||||
await oldest.save();
|
||||
return oldest;
|
||||
};
|
||||
|
||||
const User = mongoose.model("User", userSchema);
|
||||
|
||||
export default User;
|
||||
79
backend/src/routes/admin.js
Normal file
79
backend/src/routes/admin.js
Normal file
@@ -0,0 +1,79 @@
|
||||
import { Router } from "express";
|
||||
import User, { ROLES } from "../models/User.js";
|
||||
import { requireAdmin, requireAuth } from "../middleware/auth.js";
|
||||
|
||||
const router = Router();
|
||||
|
||||
/* The back office of the wiki: who holds an account, and what each of them may
|
||||
do. Everything here takes an admin — `requireAdmin` reads the role off the
|
||||
account, so a session outlives its own promotion the moment it is undone. */
|
||||
|
||||
/** The shape the dashboard is given for one account: the public fields, plus
|
||||
when it was opened. */
|
||||
function accountFor(user) {
|
||||
return { ...user.toPublic(), createdAt: user.createdAt };
|
||||
}
|
||||
|
||||
// GET /api/admin/users — every account on the wiki, newest first. The pictures
|
||||
// travel along as data URLs, which is what the list needs to look like the rest
|
||||
// of the wiki; the wiki holds a handful of accounts, not thousands.
|
||||
router.get("/users", requireAuth, requireAdmin, async (req, res, next) => {
|
||||
try {
|
||||
const users = await User.find().sort({ createdAt: -1 });
|
||||
res.json({ accounts: users.map(accountFor) });
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
|
||||
// PUT /api/admin/users/:id/role — hand the admin role to an account, or take it
|
||||
// back. An admin's own role is the one they cannot change: whoever else is
|
||||
// already an admin does that, so the wiki is never left without one.
|
||||
router.put("/users/:id/role", requireAuth, requireAdmin, async (req, res, next) => {
|
||||
try {
|
||||
const role = String(req.body?.role ?? "");
|
||||
if (!ROLES.includes(role)) {
|
||||
return res.status(400).json({ message: `Role is one of: ${ROLES.join(", ")}.` });
|
||||
}
|
||||
|
||||
const account = await User.findById(req.params.id);
|
||||
if (!account) return res.status(404).json({ message: "No such account." });
|
||||
|
||||
if (role !== "admin" && account._id.equals(req.user.id)) {
|
||||
return res
|
||||
.status(400)
|
||||
.json({ message: "Another admin has to step you down from the role." });
|
||||
}
|
||||
if (account.role === role) return res.json({ account: accountFor(account) });
|
||||
|
||||
account.role = role;
|
||||
await account.save();
|
||||
res.json({ account: accountFor(account) });
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
|
||||
// DELETE /api/admin/users/:id — close an account for good. An admin's own
|
||||
// account is the one they cannot close, the same guard as the role: somebody
|
||||
// else has to do it, so the wiki is never left without a way back in. The
|
||||
// articles outlive the account — none of them ever named an author.
|
||||
router.delete("/users/:id", requireAuth, requireAdmin, async (req, res, next) => {
|
||||
try {
|
||||
const account = await User.findById(req.params.id);
|
||||
if (!account) return res.status(404).json({ message: "No such account." });
|
||||
|
||||
if (account._id.equals(req.user.id)) {
|
||||
return res
|
||||
.status(400)
|
||||
.json({ message: "Another admin has to close your own account." });
|
||||
}
|
||||
|
||||
await account.deleteOne();
|
||||
res.json({ message: "Account deleted." });
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
361
backend/src/routes/articles.js
Normal file
361
backend/src/routes/articles.js
Normal file
@@ -0,0 +1,361 @@
|
||||
import { Router } from "express";
|
||||
import Article from "../models/Article.js";
|
||||
import { requireAuth } from "../middleware/auth.js";
|
||||
|
||||
const router = Router();
|
||||
|
||||
// Reading the wiki is open to everyone; the write endpoints at the bottom of
|
||||
// this file take an account — see routes/auth.js for how one is obtained.
|
||||
|
||||
// Convert a title (or any string) into a URL-safe slug
|
||||
export function slugify(str) {
|
||||
return String(str)
|
||||
.toLowerCase()
|
||||
.trim()
|
||||
.replace(/[^\w\s-]/g, "")
|
||||
.replace(/[\s_]+/g, "-")
|
||||
.replace(/-+/g, "-")
|
||||
.replace(/^-|-$/g, "");
|
||||
}
|
||||
|
||||
// Make a slug unique by appending -2, -3, ... if needed.
|
||||
// Optionally pass `excludeSlug` when the slug is unchanged during updates.
|
||||
async function uniqueSlug(base, excludeSlug = null) {
|
||||
const root = slugify(base) || "article";
|
||||
let candidate = root;
|
||||
let n = 1;
|
||||
// eslint-disable-next-line no-constant-condition
|
||||
while (true) {
|
||||
const existing = await Article.findOne({ slug: candidate }).select("slug").lean();
|
||||
if (!existing || existing.slug === excludeSlug) return candidate;
|
||||
candidate = `${root}-${++n}`;
|
||||
}
|
||||
}
|
||||
|
||||
// "FR " -> "fr"; whatever is stored on an article is what queries see.
|
||||
function languageCode(value) {
|
||||
const code = String(value ?? "en").trim().toLowerCase();
|
||||
return code || "en";
|
||||
}
|
||||
|
||||
// The language versions of one article: every document sharing its identity —
|
||||
// the canonical (original) version's slug. Translations carry that slug as
|
||||
// `baseSlug`; the canonical document answers to it as its own `slug`.
|
||||
async function versionsOf(identity) {
|
||||
// not lean: hydration fills in the language default for older documents
|
||||
return Article.find({ $or: [{ slug: identity }, { baseSlug: identity }] })
|
||||
.select("slug title language updatedAt")
|
||||
.sort({ language: 1 });
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve one article by its identity, optionally a specific language:
|
||||
* without `lang` the canonical version answers (or the document whose slug
|
||||
* was addressed, which also covers older `/slug-fr` addresses); with `lang`
|
||||
* the version written in that language — `/wiki/fr/euler` on the front end.
|
||||
*/
|
||||
async function resolveVersion(slug, lang) {
|
||||
const base = await Article.findOne({ slug });
|
||||
if (!lang) return base;
|
||||
const wanted = languageCode(lang);
|
||||
if (base && languageCode(base.language) === wanted) return base;
|
||||
const identity = base?.baseSlug || slug;
|
||||
// a language address with no version in that language answers honestly: 404
|
||||
return Article.findOne({ baseSlug: identity, language: wanted });
|
||||
}
|
||||
|
||||
// GET /api/articles?q=&tag=&lang= - list articles (without content body).
|
||||
// One entry per article regardless of how many languages it exists in: the
|
||||
// canonical version answers with every language version attached, and with
|
||||
// ?lang= the version written in that language answers instead.
|
||||
router.get("/", async (req, res, next) => {
|
||||
try {
|
||||
const { q, tag, lang } = req.query;
|
||||
const filter = {};
|
||||
if (typeof q === "string" && q.trim()) {
|
||||
const safe = q.trim().replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||
const rx = new RegExp(safe, "i");
|
||||
filter.$or = [{ title: rx }, { tags: rx }];
|
||||
}
|
||||
if (typeof tag === "string" && tag.trim()) {
|
||||
filter.tags = tag.trim().toLowerCase();
|
||||
}
|
||||
const wantedLang = typeof lang === "string" && lang.trim() ? languageCode(lang) : "";
|
||||
if (wantedLang) {
|
||||
// articles written before the language field existed are English
|
||||
filter.language = wantedLang === "en" ? { $in: ["en", null] } : wantedLang;
|
||||
}
|
||||
|
||||
const matched = await Article.find(filter).select("-content").sort({ updatedAt: -1 });
|
||||
if (!matched.length) return res.json([]);
|
||||
|
||||
// pull in the versions of every matched article so each can be counted
|
||||
// as one article and carry the full list of its languages
|
||||
const identities = [...new Set(matched.map((a) => a.baseSlug || a.slug))];
|
||||
const groupDocs = await Article.find({
|
||||
$or: [{ slug: { $in: identities } }, { baseSlug: { $in: identities } }],
|
||||
})
|
||||
.select("-content")
|
||||
.sort({ updatedAt: -1 }); // not lean: hydration fills in old defaults
|
||||
|
||||
const versionsByIdentity = new Map(identities.map((id) => [id, []]));
|
||||
for (const a of groupDocs) {
|
||||
versionsByIdentity.get(a.baseSlug || a.slug)?.push(a);
|
||||
}
|
||||
const matchedSlugs = new Set(matched.map((a) => a.slug));
|
||||
|
||||
const entries = identities.map((id) => {
|
||||
const group = versionsByIdentity.get(id) ?? [];
|
||||
const asVersion = (a) => ({ ...a.toObject(), versions: group });
|
||||
if (wantedLang) {
|
||||
const inWanted = group.find((a) => languageCode(a.language) === wantedLang);
|
||||
if (inWanted) return asVersion(inWanted);
|
||||
}
|
||||
const rep = group.find((a) => !a.baseSlug) ?? group.find((a) => matchedSlugs.has(a.slug)) ?? group[0];
|
||||
return asVersion(rep);
|
||||
});
|
||||
entries.sort((a, b) => new Date(b.updatedAt) - new Date(a.updatedAt));
|
||||
res.json(entries);
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
|
||||
// GET /api/articles/random - one random article. An article counts once no
|
||||
// matter how many languages it exists in, so versions ride along with their
|
||||
// canonical document; in a shelf of orphans any version stands in for itself.
|
||||
router.get("/random", async (req, res, next) => {
|
||||
try {
|
||||
const [sampled] = await Article.aggregate([
|
||||
{ $match: { baseSlug: null } },
|
||||
{ $sample: { size: 1 } },
|
||||
]);
|
||||
const [article] = sampled
|
||||
? [sampled]
|
||||
: await Article.aggregate([{ $match: { baseSlug: { $type: "string" } } }, { $sample: { size: 1 } }]);
|
||||
if (!article) return res.status(404).json({ message: "No articles yet" });
|
||||
res.json(article);
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
|
||||
// Links inside article content, as the graph sees them: wiki links
|
||||
// ([[Target]], with optional #section and |display) and markdown links
|
||||
// pointing at /wiki/<slug>. Global so String#matchAll resumes per scan.
|
||||
const WIKILINK_RX = /\[\[([^\[\]|#]+)(?:#[^\[\]|]*)?(?:\|[^\[\]]*)?\]\]/g;
|
||||
const WIKI_URL_RX = /\]\((?:https?:\/\/[^/\s)]+)?\/?wiki\/([A-Za-z0-9][A-Za-z0-9_-]*)/g;
|
||||
|
||||
// GET /api/articles/graph - the wiki's link map for the graph view: one node
|
||||
// per article — versions of the same article share a node — and one undirected
|
||||
// edge per linked pair. Code spans never draw links; self-links and links to
|
||||
// articles that don't exist drop out, and repeated links between the same pair
|
||||
// collapse into a single edge.
|
||||
router.get("/graph", async (req, res, next) => {
|
||||
try {
|
||||
const articles = await Article.find()
|
||||
.select("slug baseSlug title tags content")
|
||||
.lean();
|
||||
|
||||
const identityOf = (a) => a.baseSlug || a.slug;
|
||||
const known = new Set(articles.map(identityOf));
|
||||
const degree = new Map(articles.map((a) => [identityOf(a), 0]));
|
||||
const edges = [];
|
||||
const seen = new Set();
|
||||
|
||||
const addEdge = (from, to) => {
|
||||
if (!to || from === to || !known.has(to)) return;
|
||||
const key = from < to ? `${from}\u0000${to}` : `${to}\u0000${from}`;
|
||||
if (seen.has(key)) return;
|
||||
seen.add(key);
|
||||
edges.push({ source: from, target: to });
|
||||
degree.set(from, degree.get(from) + 1);
|
||||
degree.set(to, degree.get(to) + 1);
|
||||
};
|
||||
|
||||
for (const article of articles) {
|
||||
const content = (article.content ?? "")
|
||||
.replace(/```[\s\S]*?```/g, " ")
|
||||
.replace(/`[^`\n]*`/g, " ");
|
||||
for (const m of content.matchAll(WIKILINK_RX)) {
|
||||
addEdge(identityOf(article), slugify(m[1]));
|
||||
}
|
||||
for (const m of content.matchAll(WIKI_URL_RX)) {
|
||||
addEdge(identityOf(article), m[1].toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
// the node speaks with its canonical article's title, if it still has one
|
||||
const nodeByIdentity = new Map();
|
||||
for (const article of articles) {
|
||||
const identity = identityOf(article);
|
||||
const node = nodeByIdentity.get(identity) ?? {
|
||||
slug: identity,
|
||||
title: article.title,
|
||||
tags: [],
|
||||
links: degree.get(identity) ?? 0,
|
||||
};
|
||||
if (!article.baseSlug) node.title = article.title;
|
||||
for (const t of article.tags ?? []) if (!node.tags.includes(t)) node.tags.push(t);
|
||||
nodeByIdentity.set(identity, node);
|
||||
}
|
||||
res.json({ nodes: [...nodeByIdentity.values()], edges });
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
|
||||
// GET /api/articles/slug/:slug - get one article by slug, together with the
|
||||
// language versions the same article exists in (including itself). With
|
||||
// ?lang=fr the version written in that language answers, falling back to the
|
||||
// canonical one when it exists in no such language.
|
||||
router.get("/slug/:slug", async (req, res, next) => {
|
||||
try {
|
||||
const lang = typeof req.query.lang === "string" ? req.query.lang.trim() : "";
|
||||
const article = await resolveVersion(req.params.slug, lang);
|
||||
if (!article) return res.status(404).json({ message: "Article not found" });
|
||||
const versions = await versionsOf(article.baseSlug || article.slug);
|
||||
res.json({ ...article.toObject(), versions });
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
|
||||
// POST /api/articles - create an article (sign-in required; reading is public,
|
||||
// writing the wiki takes an account). Passing `baseSlug` makes the new document
|
||||
// another language version of an existing article rather than a fresh one: it
|
||||
// joins the original's version group and takes a slug beside it (slug-fr, …).
|
||||
router.post("/", requireAuth, async (req, res, next) => {
|
||||
try {
|
||||
const { title, content = "", tags = [], baseSlug } = req.body || {};
|
||||
const language = languageCode(req.body?.language);
|
||||
if (!title || !String(title).trim()) {
|
||||
return res.status(400).json({ message: "Title is required" });
|
||||
}
|
||||
|
||||
let identity = null;
|
||||
if (baseSlug) {
|
||||
const base = await Article.findOne({ slug: slugify(baseSlug) });
|
||||
if (!base) {
|
||||
return res.status(400).json({ message: "The article being translated does not exist" });
|
||||
}
|
||||
identity = base.baseSlug || base.slug;
|
||||
} else {
|
||||
// Two articles must not share a name in different languages: when the
|
||||
// slug is taken by an article written in another language, the document
|
||||
// joins it as a version rather than standing beside it as a twin. (The
|
||||
// same name in the same language stays the old `-2` suffixed sibling.)
|
||||
const byName = await Article.findOne({
|
||||
slug: slugify(req.body.slug || title),
|
||||
});
|
||||
if (byName && languageCode(byName.language) !== language) {
|
||||
identity = byName.baseSlug || byName.slug;
|
||||
}
|
||||
}
|
||||
if (identity) {
|
||||
const clash = await Article.findOne({
|
||||
$or: [{ slug: identity }, { baseSlug: identity }],
|
||||
language,
|
||||
});
|
||||
if (clash) {
|
||||
return res
|
||||
.status(400)
|
||||
.json({ message: `This article already has a version in ${language}` });
|
||||
}
|
||||
}
|
||||
|
||||
const requested = req.body.slug
|
||||
? slugify(req.body.slug)
|
||||
: identity
|
||||
? `${identity}-${language}` // versions sit side by side: slug-fr, slug-de, ...
|
||||
: slugify(title);
|
||||
const slug = await uniqueSlug(requested);
|
||||
const article = await Article.create({
|
||||
title,
|
||||
content,
|
||||
tags,
|
||||
language,
|
||||
slug,
|
||||
baseSlug: identity,
|
||||
});
|
||||
res.status(201).json(article);
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
|
||||
// PUT /api/articles/slug/:slug - update an article (sign-in required)
|
||||
router.put("/slug/:slug", requireAuth, async (req, res, next) => {
|
||||
try {
|
||||
const { title, content, tags, language } = req.body || {};
|
||||
if (title !== undefined && !String(title).trim()) {
|
||||
return res.status(400).json({ message: "Title is required" });
|
||||
}
|
||||
const article = await Article.findOne({ slug: req.params.slug });
|
||||
if (!article) return res.status(404).json({ message: "Article not found" });
|
||||
|
||||
const update = {};
|
||||
if (title !== undefined) update.title = title;
|
||||
if (content !== undefined) update.content = content;
|
||||
if (tags !== undefined) update.tags = tags;
|
||||
|
||||
// Moving this version to another language must not collide with a
|
||||
// version the article already has in that language.
|
||||
if (language !== undefined) {
|
||||
const code = languageCode(language);
|
||||
if (code !== article.language) {
|
||||
const identity = article.baseSlug || article.slug;
|
||||
const clash = await Article.findOne({
|
||||
$or: [{ slug: identity }, { baseSlug: identity }],
|
||||
slug: { $ne: article.slug },
|
||||
language: code,
|
||||
});
|
||||
if (clash) {
|
||||
return res
|
||||
.status(400)
|
||||
.json({ message: `This article already has a version in ${code}` });
|
||||
}
|
||||
update.language = code;
|
||||
}
|
||||
}
|
||||
|
||||
// Re-slug when the title changes and no explicit slug was provided
|
||||
if (title !== undefined) {
|
||||
const requested = req.body.slug ? slugify(req.body.slug) : slugify(title);
|
||||
if (requested && requested !== article.slug) {
|
||||
update.slug = await uniqueSlug(requested, article.slug);
|
||||
}
|
||||
}
|
||||
|
||||
const updated = await Article.findOneAndUpdate(
|
||||
{ slug: req.params.slug },
|
||||
update,
|
||||
{ new: true, runValidators: true }
|
||||
);
|
||||
|
||||
// The version group's identity is the canonical article's slug: when the
|
||||
// canonical is renamed, its translations follow it to the new slug.
|
||||
if (updated && !article.baseSlug && update.slug) {
|
||||
await Article.updateMany({ baseSlug: article.slug }, { baseSlug: update.slug });
|
||||
}
|
||||
|
||||
res.json(updated);
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
|
||||
// DELETE /api/articles/slug/:slug - delete an article (sign-in required).
|
||||
// Deleting the canonical version leaves its translations readable: they still
|
||||
// recognise each other through the baseSlug they share.
|
||||
router.delete("/slug/:slug", requireAuth, async (req, res, next) => {
|
||||
try {
|
||||
const deleted = await Article.findOneAndDelete({ slug: req.params.slug });
|
||||
if (!deleted) return res.status(404).json({ message: "Article not found" });
|
||||
res.status(204).send();
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
189
backend/src/routes/auth.js
Normal file
189
backend/src/routes/auth.js
Normal file
@@ -0,0 +1,189 @@
|
||||
import { Router } from "express";
|
||||
import User, {
|
||||
SUPPORTED_LOCALES,
|
||||
USERNAME_REGEX,
|
||||
USERNAME_MESSAGE,
|
||||
PASSWORD_MIN,
|
||||
PASSWORD_MESSAGE,
|
||||
credentialProblem,
|
||||
} from "../models/User.js";
|
||||
import { requireAuth, signToken } from "../middleware/auth.js";
|
||||
|
||||
const router = Router();
|
||||
|
||||
/* A profile picture arrives as a data URL the frontend shrank. The cap sits
|
||||
under the JSON body limit in index.js: anything that slips past the
|
||||
frontend's own resizing still cannot fill a request whole. */
|
||||
const AVATAR_MAX_CHARS = 1_000_000;
|
||||
const AVATAR_REGEX = /^data:image\/(png|jpe?g|webp|gif);base64,[A-Za-z0-9+/=]+$/;
|
||||
|
||||
/* Register and login share a shape: a token for whoever the account turns out
|
||||
to be, plus the few public fields the frontend displays. */
|
||||
function sessionFor(user) {
|
||||
return { token: signToken(user), user: user.toPublic() };
|
||||
}
|
||||
|
||||
function readCredentials(body) {
|
||||
return {
|
||||
username: String(body?.username ?? "").trim().toLowerCase(),
|
||||
// A password is taken exactly as typed — only the username is normalised.
|
||||
password: String(body?.password ?? ""),
|
||||
};
|
||||
}
|
||||
|
||||
// POST /api/auth/register — open an account and sign straight into it
|
||||
router.post("/register", async (req, res, next) => {
|
||||
try {
|
||||
const credentials = readCredentials(req.body);
|
||||
const problem = credentialProblem(credentials);
|
||||
if (problem) return res.status(400).json({ message: problem });
|
||||
|
||||
const user = new User({ username: credentials.username });
|
||||
/* The wiki's very first account is its admin: somebody has to be able to
|
||||
open the dashboard and hand the role to anyone else. (Two registrations
|
||||
racing on an empty wiki could both see it empty; the name is still decided
|
||||
by the unique index, and another admin can undo the extra role at once.) */
|
||||
if (await User.hasNone()) user.role = "admin";
|
||||
await user.setPassword(credentials.password);
|
||||
try {
|
||||
await user.save();
|
||||
} catch (err) {
|
||||
// Two registrations for the same name at once: the unique index decides.
|
||||
if (err?.code === 11000) {
|
||||
return res.status(409).json({ message: "That username is taken." });
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
res.status(201).json(sessionFor(user));
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
|
||||
// POST /api/auth/login — swap a username and password for a session token
|
||||
router.post("/login", async (req, res, next) => {
|
||||
try {
|
||||
const { username, password } = readCredentials(req.body);
|
||||
const user = await User.findOne({ username }).select("+passwordHash");
|
||||
|
||||
// Wrong name and wrong password answer alike, so the form gives nothing
|
||||
// away about which accounts exist.
|
||||
if (!user || !(await user.checkPassword(password))) {
|
||||
return res.status(401).json({ message: "Wrong username or password." });
|
||||
}
|
||||
res.json(sessionFor(user));
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
|
||||
// GET /api/auth/me — who a token belongs to; the frontend asks this on load
|
||||
router.get("/me", requireAuth, async (req, res, next) => {
|
||||
try {
|
||||
const user = await User.findById(req.user.id);
|
||||
if (!user) return res.status(401).json({ message: "No such account any more." });
|
||||
res.json({ user: user.toPublic() });
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
|
||||
// PUT /api/auth/me — change the username on the account the token belongs to
|
||||
router.put("/me", requireAuth, async (req, res, next) => {
|
||||
try {
|
||||
const username = String(req.body?.username ?? "").trim().toLowerCase();
|
||||
if (!USERNAME_REGEX.test(username)) {
|
||||
return res.status(400).json({ message: USERNAME_MESSAGE });
|
||||
}
|
||||
|
||||
const user = await User.findById(req.user.id);
|
||||
if (!user) return res.status(401).json({ message: "No such account any more." });
|
||||
if (user.username === username) return res.json({ user: user.toPublic() });
|
||||
|
||||
user.username = username;
|
||||
try {
|
||||
await user.save();
|
||||
} catch (err) {
|
||||
// Someone else claimed the name while this was in flight.
|
||||
if (err?.code === 11000) {
|
||||
return res.status(409).json({ message: "That username is taken." });
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
res.json({ user: user.toPublic() });
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
|
||||
// PUT /api/auth/password — swap the current password for a new one. The
|
||||
// current one is asked for, so a stolen token alone cannot lock its owner out.
|
||||
router.put("/password", requireAuth, async (req, res, next) => {
|
||||
try {
|
||||
const currentPassword = String(req.body?.currentPassword ?? "");
|
||||
const newPassword = String(req.body?.newPassword ?? "");
|
||||
if (newPassword.length < PASSWORD_MIN) {
|
||||
return res.status(400).json({ message: PASSWORD_MESSAGE });
|
||||
}
|
||||
if (newPassword.length > 200) {
|
||||
return res.status(400).json({ message: "Password is too long." });
|
||||
}
|
||||
|
||||
const user = await User.findById(req.user.id).select("+passwordHash");
|
||||
if (!user) return res.status(401).json({ message: "No such account any more." });
|
||||
if (!(await user.checkPassword(currentPassword))) {
|
||||
return res.status(401).json({ message: "That is not your current password." });
|
||||
}
|
||||
|
||||
await user.setPassword(newPassword);
|
||||
await user.save();
|
||||
res.json({ user: user.toPublic() });
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
|
||||
// PUT /api/auth/locale — the interface language saved on the account, so the
|
||||
// choice follows the person across devices; "" hands the decision back to the
|
||||
// browser. Only the supported languages are accepted.
|
||||
router.put("/locale", requireAuth, async (req, res, next) => {
|
||||
try {
|
||||
const locale = String(req.body?.locale ?? "").trim().toLowerCase();
|
||||
if (locale && !SUPPORTED_LOCALES.includes(locale)) {
|
||||
return res.status(400).json({ message: `Language is one of: ${SUPPORTED_LOCALES.join(", ")}.` });
|
||||
}
|
||||
|
||||
const user = await User.findById(req.user.id);
|
||||
if (!user) return res.status(401).json({ message: "No such account any more." });
|
||||
user.locale = locale;
|
||||
await user.save();
|
||||
res.json({ user: user.toPublic() });
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
|
||||
// PUT /api/auth/avatar — a new profile picture as a data URL; "" removes it
|
||||
router.put("/avatar", requireAuth, async (req, res, next) => {
|
||||
try {
|
||||
const avatar = String(req.body?.avatar ?? "");
|
||||
if (avatar) {
|
||||
if (avatar.length > AVATAR_MAX_CHARS) {
|
||||
return res.status(413).json({ message: "That picture is too large." });
|
||||
}
|
||||
if (!AVATAR_REGEX.test(avatar)) {
|
||||
return res.status(400).json({ message: "Send a PNG, JPEG, WebP or GIF image." });
|
||||
}
|
||||
}
|
||||
|
||||
const user = await User.findById(req.user.id);
|
||||
if (!user) return res.status(401).json({ message: "No such account any more." });
|
||||
user.avatar = avatar;
|
||||
await user.save();
|
||||
res.json({ user: user.toPublic() });
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
62
backend/src/routes/items.js
Normal file
62
backend/src/routes/items.js
Normal file
@@ -0,0 +1,62 @@
|
||||
import { Router } from "express";
|
||||
import Item from "../models/Item.js";
|
||||
|
||||
const router = Router();
|
||||
|
||||
// GET /api/items - list all items
|
||||
router.get("/", async (req, res, next) => {
|
||||
try {
|
||||
const items = await Item.find().sort({ createdAt: -1 });
|
||||
res.json(items);
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
|
||||
// GET /api/items/:id - get one item
|
||||
router.get("/:id", async (req, res, next) => {
|
||||
try {
|
||||
const item = await Item.findById(req.params.id);
|
||||
if (!item) return res.status(404).json({ message: "Item not found" });
|
||||
res.json(item);
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
|
||||
// POST /api/items - create an item
|
||||
router.post("/", async (req, res, next) => {
|
||||
try {
|
||||
const item = await Item.create(req.body);
|
||||
res.status(201).json(item);
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
|
||||
// PUT /api/items/:id - update an item
|
||||
router.put("/:id", async (req, res, next) => {
|
||||
try {
|
||||
const item = await Item.findByIdAndUpdate(req.params.id, req.body, {
|
||||
new: true,
|
||||
runValidators: true,
|
||||
});
|
||||
if (!item) return res.status(404).json({ message: "Item not found" });
|
||||
res.json(item);
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
|
||||
// DELETE /api/items/:id - delete an item
|
||||
router.delete("/:id", async (req, res, next) => {
|
||||
try {
|
||||
const item = await Item.findByIdAndDelete(req.params.id);
|
||||
if (!item) return res.status(404).json({ message: "Item not found" });
|
||||
res.status(204).send();
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
410
backend/src/seed.js
Normal file
410
backend/src/seed.js
Normal file
@@ -0,0 +1,410 @@
|
||||
import "dotenv/config";
|
||||
import mongoose from "mongoose";
|
||||
import { connectDB, disconnectDB } from "./config/db.js";
|
||||
import Article from "./models/Article.js";
|
||||
|
||||
const articles = [
|
||||
{
|
||||
slug: "pythagorean-theorem",
|
||||
title: "Pythagorean theorem",
|
||||
tags: ["geometry", "euclidean", "triangles"],
|
||||
content: `# Pythagorean theorem
|
||||
|
||||
In Euclidean geometry, the **Pythagorean theorem** states that in a right-angled triangle, the area of the square on the hypotenuse is equal to the sum of the areas of the squares on the other two sides:
|
||||
|
||||
$$
|
||||
a^2 + b^2 = c^2
|
||||
$$
|
||||
|
||||
where $c$ denotes the length of the hypotenuse and $a$ and $b$ the lengths of the other two sides.
|
||||
|
||||
## Examples
|
||||
|
||||
- A $(3, 4, 5)$ triangle: $3^2 + 4^2 = 9 + 16 = 25 = 5^2$ ✓
|
||||
- A $(5, 12, 13)$ triangle: $5^2 + 12^2 = 25 + 144 = 169 = 13^2$ ✓
|
||||
|
||||
## A proof by rearrangement
|
||||
|
||||
Consider a square of side $a+b$. Its area can be computed two ways:
|
||||
|
||||
$$
|
||||
(a+b)^2 = 4 \\cdot \\frac{1}{2}ab + c^2
|
||||
$$
|
||||
|
||||
Expanding the left side gives $a^2 + 2ab + b^2 = 2ab + c^2$, and subtracting $2ab$ from both sides yields $a^2 + b^2 = c^2$. $\\blacksquare$
|
||||
|
||||
## Generalizations
|
||||
|
||||
| Theorem | Setting | Formula |
|
||||
| --- | --- | --- |
|
||||
| Law of cosines | Euclidean | $c^2 = a^2 + b^2 - 2ab\\cos\\gamma$ |
|
||||
| de Gua's theorem | 3D (tetrahedron) | $V_0^2 = V_1^2 + V_2^2 + V_3^2$ |
|
||||
|
||||
> The theorem is named after Pythagoras of Samos (c. 570 – c. 495 BC), although Babylonian tablets such as Plimpton 322 predate him by a millennium.
|
||||
|
||||
## Distance formula
|
||||
|
||||
The theorem underpins the Euclidean distance between two points $P_1=(x_1, y_1)$ and $P_2=(x_2, y_2)$:
|
||||
|
||||
$$
|
||||
d = \\sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}
|
||||
$$
|
||||
`,
|
||||
},
|
||||
{
|
||||
slug: "eulers-identity",
|
||||
title: "Euler's identity",
|
||||
tags: ["complex analysis", "constants", "analysis"],
|
||||
content: `# Euler's identity
|
||||
|
||||
**Euler's identity** is the equality
|
||||
|
||||
$$
|
||||
e^{i\\pi} + 1 = 0
|
||||
$$
|
||||
|
||||
It is a special case of Euler's formula $e^{i\\theta} = \\cos\\theta + i\\sin\\theta$ evaluated at $\\theta = \\pi$.
|
||||
|
||||
## Why it is celebrated
|
||||
|
||||
The identity links five fundamental constants:
|
||||
|
||||
| Constant | Significance |
|
||||
| --- | --- |
|
||||
| $e$ | base of the natural logarithm |
|
||||
| $i$ | the imaginary unit, $i^2 = -1$ |
|
||||
| $\\pi$ | ratio of circumference to diameter |
|
||||
| $1$ | multiplicative identity |
|
||||
| $0$ | additive identity |
|
||||
|
||||
...using only the operations of exponentiation, multiplication (implicit), and addition.
|
||||
|
||||
## Derivation from Taylor series
|
||||
|
||||
These series are Taylor expansions at $0$, assembled from [[Derivative|derivatives]]:
|
||||
|
||||
$$
|
||||
e^x = \\sum_{n=0}^{\\infty} \\frac{x^n}{n!}, \\quad
|
||||
\\cos x = \\sum_{n=0}^{\\infty} \\frac{(-1)^n x^{2n}}{(2n)!}, \\quad
|
||||
\\sin x = \\sum_{n=0}^{\\infty} \\frac{(-1)^n x^{2n+1}}{(2n+1)!}
|
||||
$$
|
||||
|
||||
substituting $x = i\\theta$ and separating real and imaginary parts gives Euler's formula. Setting $\\theta = \\pi$:
|
||||
|
||||
$$
|
||||
e^{i\\pi} = \\cos\\pi + i\\sin\\pi = -1 + 0i = -1
|
||||
$$
|
||||
|
||||
## General case
|
||||
|
||||
For any integer $k$, the $n$-th roots of unity satisfy
|
||||
|
||||
$$
|
||||
z_k = e^{2\\pi i k / n}, \\qquad k = 0, 1, \\dots, n-1
|
||||
$$
|
||||
|
||||
and Euler's identity is the case $n = 2$, $k = 1$. Split the fifth roots ($n = 5$) and the [[Golden ratio|golden ratio]] turns up: $\\cos 72^\\circ = (\\sqrt{5} - 1)/4$.
|
||||
|
||||
> "Like a Shakespearean sonnet that captures the very essence of love, or a painting that brings out the beauty of the human form, Euler's equation reaches down into the very depths of existence." — Keith Devlin
|
||||
`,
|
||||
},
|
||||
{
|
||||
slug: "derivative",
|
||||
title: "Derivative",
|
||||
tags: ["calculus", "analysis", "foundations"],
|
||||
content: `# Derivative
|
||||
|
||||
In mathematics, the **derivative** of a function of one variable at a point is the rate of change of the function near that point — the slope of the tangent line to the graph of the function at that point.
|
||||
|
||||
## Definition
|
||||
|
||||
The derivative of $f$ at $x$ is defined as the limit of the difference quotient:
|
||||
|
||||
$$
|
||||
f'(x) = \\lim_{h \\to 0} \\frac{f(x+h) - f(x)}{h}
|
||||
$$
|
||||
|
||||
if this limit exists. An equivalent formulation:
|
||||
|
||||
$$
|
||||
f'(a) = \\lim_{x \\to a} \\frac{f(x) - f(a)}{x - a}
|
||||
$$
|
||||
|
||||
## Basic rules
|
||||
|
||||
Let $u$ and $v$ be differentiable functions. Then:
|
||||
|
||||
| Rule | Formula |
|
||||
| --- | --- |
|
||||
| Sum | $(u+v)' = u' + v'$ |
|
||||
| Product | $(uv)' = u'v + uv'$ |
|
||||
| Quotient | $\\left(\\frac{u}{v}\\right)' = \\frac{u'v - uv'}{v^2}$ |
|
||||
| Chain | $(u \\circ v)'(x) = u'(v(x)) \\cdot v'(x)$ |
|
||||
|
||||
## Common derivatives
|
||||
|
||||
$$
|
||||
\\frac{d}{dx} x^n = n x^{n-1}, \\qquad
|
||||
\\frac{d}{dx} e^x = e^x, \\qquad
|
||||
\\frac{d}{dx} \\ln x = \\frac{1}{x}
|
||||
$$
|
||||
|
||||
$$
|
||||
\\frac{d}{dx} \\sin x = \\cos x, \\qquad
|
||||
\\frac{d}{dx} \\cos x = -\\sin x
|
||||
$$
|
||||
|
||||
## Example
|
||||
|
||||
For $f(x) = x^3$, the difference quotient is
|
||||
|
||||
$$
|
||||
\\frac{(x+h)^3 - x^3}{h} = \\frac{3x^2h + 3xh^2 + h^3}{h} = 3x^2 + 3xh + h^2 \\xrightarrow{h \\to 0} 3x^2
|
||||
$$
|
||||
|
||||
so $f'(x) = 3x^2$.
|
||||
|
||||
## Numerical check
|
||||
|
||||
\`\`\`python
|
||||
def derivative(f, x, h=1e-8):
|
||||
return (f(x + h) - f(x)) / h
|
||||
|
||||
f = lambda x: x**3
|
||||
print(derivative(f, 2.0)) # ~12.0
|
||||
\`\`\`
|
||||
|
||||
## Related concepts
|
||||
|
||||
- The **integral** is, roughly, the inverse operation (see [[Fundamental theorem of calculus]]).
|
||||
- A function whose derivative exists everywhere is called *differentiable*; differentiability implies *continuity*, but not conversely (e.g. $f(x) = |x|$ at $x = 0$).
|
||||
`,
|
||||
},
|
||||
{
|
||||
slug: "bayes-theorem",
|
||||
title: "Bayes' theorem",
|
||||
tags: ["probability", "statistics", "machine learning"],
|
||||
content: `# Bayes' theorem
|
||||
|
||||
**Bayes' theorem** describes how the probability of an event should be updated given prior knowledge related to the event. It is the foundation of Bayesian statistics.
|
||||
|
||||
## Statement
|
||||
|
||||
For events $A$ and $B$ with $P(B) \\neq 0$:
|
||||
|
||||
$$
|
||||
P(A \\mid B) = \\frac{P(B \\mid A)\\, P(A)}{P(B)}
|
||||
$$
|
||||
|
||||
In terms of a *hypothesis* $H$ and *evidence* $E$:
|
||||
|
||||
$$
|
||||
\\underbrace{P(H \\mid E)}_{\\text{posterior}} =
|
||||
\\frac{\\overbrace{P(E \\mid H)}^{\\text{likelihood}} \\cdot \\overbrace{P(H)}^{\\text{prior}}}
|
||||
{\\underbrace{P(E)}_{\\text{evidence}}}
|
||||
$$
|
||||
|
||||
## The law of total probability
|
||||
|
||||
The denominator can be expanded when $H_1, \\dots, H_n$ partition the sample space:
|
||||
|
||||
$$
|
||||
P(E) = \\sum_{i=1}^{n} P(E \\mid H_i) P(H_i)
|
||||
$$
|
||||
|
||||
## Example: medical testing
|
||||
|
||||
A disease affects 1% of the population ($P(D) = 0.01$). A test is 99% sensitive and 95% specific. What is the probability that a positive test result means the patient has the disease?
|
||||
|
||||
$$
|
||||
P(D \\mid +) = \\frac{P(+ \\mid D) P(D)}{P(+ \\mid D)P(D) + P(+ \\mid D^c)P(D^c)}
|
||||
= \\frac{0.99 \\cdot 0.01}{0.99 \\cdot 0.01 + 0.05 \\cdot 0.99} \\approx 0.167
|
||||
$$
|
||||
|
||||
Even a positive result implies only a **16.7%** chance of disease — the base rate dominates. This is the *base rate fallacy*.
|
||||
|
||||
## Conjugate priors
|
||||
|
||||
For a Bernoulli likelihood with $\\mathrm{Beta}(\\alpha, \\beta)$ prior:
|
||||
|
||||
$$
|
||||
\\theta \\mid \\text{data} \\sim \\mathrm{Beta}\\!\\left(\\alpha + \\sum_i x_i, \\; \\beta + n - \\sum_i x_i\\right)
|
||||
$$
|
||||
|
||||
the posterior remains in the same family — a computationally convenient property. When the data are noisy measurements rather than counts, the likelihood is usually a [[Normal distribution]], and the same machinery keeps the posterior normal.
|
||||
`,
|
||||
},
|
||||
{
|
||||
slug: "golden-ratio",
|
||||
title: "Golden ratio",
|
||||
tags: ["number theory", "geometry", "sequences"],
|
||||
content: `# Golden ratio
|
||||
|
||||
The **golden ratio** $\\varphi$ (phi) is the positive number satisfying
|
||||
|
||||
$$
|
||||
\\varphi = 1 + \\frac{1}{\\varphi}
|
||||
$$
|
||||
|
||||
which gives the closed form
|
||||
|
||||
$$
|
||||
\\varphi = \\frac{1 + \\sqrt{5}}{2} = 1.6180339887\\ldots
|
||||
$$
|
||||
|
||||
The $\\sqrt{5}$ is no accident — by the [[Pythagorean theorem]] it is the hypotenuse of a right triangle with legs $1$ and $2$.
|
||||
|
||||
## Geometric definition
|
||||
|
||||
Two quantities $a$ and $b$ (with $a > b > 0$) are in the golden ratio when
|
||||
|
||||
$$
|
||||
\\frac{a+b}{a} = \\frac{a}{b} = \\varphi
|
||||
$$
|
||||
|
||||
## Connection to Fibonacci
|
||||
|
||||
The ratio of consecutive Fibonacci numbers converges to $\\varphi$:
|
||||
|
||||
$$
|
||||
\\lim_{n \\to \\infty} \\frac{F_{n+1}}{F_n} = \\varphi
|
||||
$$
|
||||
|
||||
Using Binet's formula,
|
||||
|
||||
$$
|
||||
F_n = \\frac{\\varphi^n - \\psi^n}{\\sqrt{5}}, \\qquad \\psi = \\frac{1 - \\sqrt{5}}{2} = -\\frac{1}{\\varphi}
|
||||
$$
|
||||
|
||||
## Properties
|
||||
|
||||
- $\\varphi^2 = \\varphi + 1$, so $\\varphi^3 = 2\\varphi + 1$, etc.
|
||||
- $\\dfrac{1}{\\varphi} = \\varphi - 1 = 0.6180\\ldots$
|
||||
- Continued fraction: $\\varphi = 1 + \\cfrac{1}{1 + \\cfrac{1}{1 + \\cfrac{1}{\\ddots}}}$ — the "most irrational" number, since all partial quotients are 1.
|
||||
|
||||
## In geometry
|
||||
|
||||
The diagonal of a regular pentagon is $\\varphi$ times its side. In a regular pentagon with side $s$:
|
||||
|
||||
$$
|
||||
d = \\varphi s
|
||||
$$
|
||||
|
||||
The *golden spiral* is formed by quarter-circles inscribed in golden rectangles.
|
||||
|
||||
> Beware: many claimed appearances of $\\varphi$ in art and nature (the Parthenon, the nautilus shell) are folklore rather than measurement.
|
||||
`,
|
||||
},
|
||||
{
|
||||
slug: "fundamental-theorem-of-calculus",
|
||||
title: "Fundamental theorem of calculus",
|
||||
tags: ["calculus", "analysis", "foundations"],
|
||||
content: `# Fundamental theorem of calculus
|
||||
|
||||
The **fundamental theorem of calculus** (FTC) links the two central operations of calculus: [[Derivative|differentiation]] and integration.
|
||||
|
||||
## Part I
|
||||
|
||||
If $f$ is continuous on $[a, b]$ and
|
||||
|
||||
$$
|
||||
F(x) = \\int_a^x f(t)\\, dt
|
||||
$$
|
||||
|
||||
then $F$ is differentiable on $(a, b)$ and
|
||||
|
||||
$$
|
||||
F'(x) = f(x)
|
||||
$$
|
||||
|
||||
## Part II
|
||||
|
||||
If $f$ is continuous on $[a, b]$ and $G$ is any antiderivative of $f$, then
|
||||
|
||||
$$
|
||||
\\int_a^b f(x)\\, dx = G(b) - G(a)
|
||||
$$
|
||||
|
||||
## Example
|
||||
|
||||
Compute $\\displaystyle\\int_0^1 x^2\\, dx$:
|
||||
|
||||
$$
|
||||
\\int_0^1 x^2\\, dx = \\left[ \\frac{x^3}{3} \\right]_0^1 = \\frac{1}{3} - 0 = \\frac{1}{3}
|
||||
$$
|
||||
|
||||
## Why it matters
|
||||
|
||||
- It turns *area computations* into *anti-differentiation* — a purely algebraic task.
|
||||
- Part I guarantees antiderivatives exist for every continuous function.
|
||||
- In numerical analysis, the error of quadrature rules is typically expressed through derivatives of the integrand — e.g. the trapezoidal rule error $\\displaystyle \\frac{(b-a)^3}{12} f''(\\xi)$.
|
||||
|
||||
## Sketch of the proof of Part I
|
||||
|
||||
For $h > 0$:
|
||||
|
||||
$$
|
||||
\\frac{F(x+h) - F(x)}{h} = \\frac{1}{h}\\int_x^{x+h} f(t)\\,dt
|
||||
$$
|
||||
|
||||
Since $f$ is continuous, the average value of $f$ over $[x, x+h]$ lies between $\\min_{[x,x+h]} f$ and $\\max_{[x,x+h]} f$, both of which tend to $f(x)$ as $h \\to 0$. $\\blacksquare$
|
||||
`,
|
||||
},
|
||||
{
|
||||
slug: "normal-distribution",
|
||||
title: "Normal distribution",
|
||||
tags: ["probability", "statistics", "distributions"],
|
||||
content: `# Normal distribution
|
||||
|
||||
The **normal distribution** (or *Gaussian*) with mean $\\mu$ and variance $\\sigma^2$ has density
|
||||
|
||||
$$
|
||||
f(x) = \\frac{1}{\\sigma\\sqrt{2\\pi}} \\, e^{-\\frac{(x-\\mu)^2}{2\\sigma^2}}
|
||||
$$
|
||||
|
||||
## Total probability
|
||||
|
||||
A density must integrate to one — the [[Fundamental theorem of calculus]] at work, with the Gaussian integral $\\int_{-\\infty}^{\\infty} e^{-x^2}\\,dx = \\sqrt{\\pi}$ supplying the normalising constant.
|
||||
|
||||
## In Bayesian inference
|
||||
|
||||
For noisy measurements the normal is the standard likelihood, and the conjugate-prior machinery of [[Bayes' theorem]] keeps the posterior normal whenever the prior is:
|
||||
|
||||
$$
|
||||
\\mu \\mid \\text{data} \\sim \\mathcal{N}\\!\\left(\\frac{n\\bar{x}/\\sigma^2 + \\mu_0/\\tau^2}{n/\\sigma^2 + 1/\\tau^2},\\; \\left(\\frac{n}{\\sigma^2} + \\frac{1}{\\tau^2}\\right)^{-1}\\right)
|
||||
$$
|
||||
|
||||
## Why it is everywhere
|
||||
|
||||
The central limit theorem explains the ubiquity: sums of many small independent effects drift toward the bell curve, whatever the individual effects look like.
|
||||
`,
|
||||
},
|
||||
];
|
||||
|
||||
async function seed() {
|
||||
await connectDB();
|
||||
let created = 0;
|
||||
let updated = 0;
|
||||
for (const a of articles) {
|
||||
const existing = await Article.findOne({ slug: a.slug });
|
||||
if (existing) {
|
||||
// only fill content if article is empty, never clobber user edits
|
||||
if (!existing.content) {
|
||||
Object.assign(existing, a);
|
||||
await existing.save();
|
||||
updated++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
await Article.create(a);
|
||||
created++;
|
||||
}
|
||||
console.log(`Seed complete: ${created} created, ${updated} filled, ${articles.length - created - updated} skipped`);
|
||||
await disconnectDB();
|
||||
}
|
||||
|
||||
seed().catch(async (err) => {
|
||||
console.error("Seed failed:", err.message);
|
||||
await mongoose.disconnect().catch(() => {});
|
||||
process.exit(1);
|
||||
});
|
||||
158
dev.sh
Executable file
158
dev.sh
Executable file
@@ -0,0 +1,158 @@
|
||||
#!/usr/bin/env bash
|
||||
# dev.sh — start/stop the frontend (Nuxt) and backend (Express) together.
|
||||
#
|
||||
# Usage:
|
||||
# ./dev.sh Start both in the foreground (Ctrl+C stops both)
|
||||
# ./dev.sh start Start both dev servers in the background
|
||||
# ./dev.sh stop Stop both dev servers
|
||||
# ./dev.sh restart Stop then start
|
||||
# ./dev.sh status Show which services are running
|
||||
# ./dev.sh logs [service] Follow logs (all, backend, or frontend)
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PID_DIR="$ROOT/.pids"
|
||||
LOG_DIR="$ROOT/.logs"
|
||||
SERVICES=("backend" "frontend")
|
||||
|
||||
pid_of() {
|
||||
local pid_file="$PID_DIR/$1.pid"
|
||||
[[ -f "$pid_file" ]] && cat "$pid_file" || true
|
||||
}
|
||||
|
||||
is_running() {
|
||||
local pid
|
||||
pid="$(pid_of "$1")"
|
||||
[[ -n "$pid" ]] && kill -0 "$pid" 2>/dev/null
|
||||
}
|
||||
|
||||
start_service() {
|
||||
local name="$1"
|
||||
if is_running "$name"; then
|
||||
echo "$name is already running (PID $(pid_of "$name"))"
|
||||
return
|
||||
fi
|
||||
mkdir -p "$PID_DIR" "$LOG_DIR"
|
||||
# setsid puts each service in its own process group so `stop` can kill
|
||||
# npm and all of its child processes (node --watch, nuxt, ...) cleanly.
|
||||
setsid bash -c 'cd "$1" && exec npm run dev' _ "$ROOT/$name" \
|
||||
> "$LOG_DIR/$name.log" 2>&1 &
|
||||
local pid=$!
|
||||
echo "$pid" > "$PID_DIR/$name.pid"
|
||||
echo "started $name (PID $pid) — log: $LOG_DIR/$name.log"
|
||||
}
|
||||
|
||||
stop_service() {
|
||||
local name="$1"
|
||||
local pid
|
||||
pid="$(pid_of "$name")"
|
||||
|
||||
if ! is_running "$name"; then
|
||||
echo "$name is not running"
|
||||
rm -f "$PID_DIR/$name.pid"
|
||||
return
|
||||
fi
|
||||
|
||||
# Negative PID kills the whole process group (npm + its children).
|
||||
kill -TERM -- "-$pid" 2>/dev/null || kill -TERM "$pid" 2>/dev/null || true
|
||||
# Wait up to 5s for a graceful shutdown, then force-kill.
|
||||
for _ in {1..50}; do
|
||||
kill -0 "$pid" 2>/dev/null || break
|
||||
sleep 0.1
|
||||
done
|
||||
if kill -0 "$pid" 2>/dev/null; then
|
||||
kill -KILL -- "-$pid" 2>/dev/null || kill -KILL "$pid" 2>/dev/null || true
|
||||
fi
|
||||
rm -f "$PID_DIR/$name.pid"
|
||||
echo "stopped $name (PID $pid)"
|
||||
}
|
||||
|
||||
status() {
|
||||
for name in "${SERVICES[@]}"; do
|
||||
if is_running "$name"; then
|
||||
echo "$name: running (PID $(pid_of "$name"))"
|
||||
else
|
||||
echo "$name: stopped"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
FG_PIDS=()
|
||||
SHUTTING=0
|
||||
|
||||
# Stop all foreground services (and their process groups). A second call
|
||||
# (e.g. pressing Ctrl+C again while shutting down) escalates to SIGKILL.
|
||||
fg_stop_all() {
|
||||
local name pid sig=TERM
|
||||
if [[ $SHUTTING -eq 1 ]]; then sig=KILL; else
|
||||
SHUTTING=1
|
||||
echo
|
||||
echo "stopping frontend + backend..."
|
||||
fi
|
||||
for pid in "${FG_PIDS[@]:-}"; do
|
||||
kill -"$sig" -- "-$pid" 2>/dev/null || kill -"$sig" "$pid" 2>/dev/null || true
|
||||
done
|
||||
wait 2>/dev/null || true
|
||||
for name in "${SERVICES[@]}"; do rm -f "$PID_DIR/$name.pid"; done
|
||||
exit 0
|
||||
}
|
||||
|
||||
foreground() {
|
||||
local name
|
||||
for name in "${SERVICES[@]}"; do
|
||||
if is_running "$name"; then
|
||||
echo "$name is already running (PID $(pid_of "$name")); run '$0 stop' first" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
mkdir -p "$PID_DIR"
|
||||
for name in "${SERVICES[@]}"; do
|
||||
# setsid puts each service in its own process group (PID == PGID) so the
|
||||
# output prefix pipeline survives the shutdown; sed -u tags every line.
|
||||
setsid bash -c 'cd "$1" && exec npm run dev' _ "$ROOT/$name" \
|
||||
> >(sed -u "s/^/[$name] /") 2>&1 &
|
||||
local pid=$!
|
||||
FG_PIDS+=("$pid")
|
||||
echo "$pid" > "$PID_DIR/$name.pid"
|
||||
done
|
||||
trap 'fg_stop_all' INT TERM
|
||||
echo "frontend + backend running — press Ctrl+C to stop both"
|
||||
# Exit as soon as either service dies, so they always run/stop together.
|
||||
wait -n
|
||||
echo "a dev server exited — stopping the other one..."
|
||||
fg_stop_all
|
||||
}
|
||||
|
||||
case "${1:-dev}" in
|
||||
dev)
|
||||
foreground
|
||||
;;
|
||||
start)
|
||||
for name in "${SERVICES[@]}"; do start_service "$name"; done
|
||||
echo
|
||||
echo "backend: http://localhost:5000"
|
||||
echo "frontend: http://localhost:3000"
|
||||
;;
|
||||
stop)
|
||||
for name in "${SERVICES[@]}"; do stop_service "$name"; done
|
||||
;;
|
||||
restart)
|
||||
for name in "${SERVICES[@]}"; do stop_service "$name"; done
|
||||
for name in "${SERVICES[@]}"; do start_service "$name"; done
|
||||
;;
|
||||
status)
|
||||
status
|
||||
;;
|
||||
logs)
|
||||
case "${2:-all}" in
|
||||
all) tail -f "$LOG_DIR"/*.log ;;
|
||||
backend|frontend) tail -f "$LOG_DIR/$2.log" ;;
|
||||
*) echo "usage: $0 logs [all|backend|frontend]"; exit 1 ;;
|
||||
esac
|
||||
;;
|
||||
*)
|
||||
echo "usage: $0 [dev|start|stop|restart|status|logs [all|backend|frontend]] (default: dev)"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
24
frontend/.gitignore
vendored
Normal file
24
frontend/.gitignore
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
# Nuxt dev/build outputs
|
||||
.output
|
||||
.data
|
||||
.nuxt
|
||||
.nitro
|
||||
.cache
|
||||
dist
|
||||
|
||||
# Node dependencies
|
||||
node_modules
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
|
||||
# Misc
|
||||
.DS_Store
|
||||
.fleet
|
||||
.idea
|
||||
|
||||
# Local env files
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
67
frontend/README.md
Normal file
67
frontend/README.md
Normal file
@@ -0,0 +1,67 @@
|
||||
# Mathew — a wiki for mathematics
|
||||
|
||||
A modern math-concept wiki. Articles are written in **Markdown** (with **LaTeX** via KaTeX)
|
||||
and stored in MongoDB through an Express API.
|
||||
|
||||
```
|
||||
mathew/
|
||||
├── backend/ Express 5 + Mongoose API (port 5000)
|
||||
└── frontend/ Nuxt 4 wiki UI (port 3000/3001)
|
||||
```
|
||||
|
||||
## Quick start
|
||||
|
||||
```bash
|
||||
# 1. API (requires MongoDB on localhost:27017)
|
||||
cd backend
|
||||
npm install
|
||||
npm run seed # optional: 6 sample articles (LaTeX included)
|
||||
npm run dev # → http://localhost:5000
|
||||
|
||||
# 2. UI
|
||||
cd ../frontend
|
||||
npm install
|
||||
npm run dev # → http://localhost:3000
|
||||
```
|
||||
|
||||
## Pages
|
||||
|
||||
| Route | What it does |
|
||||
| --- | --- |
|
||||
| `/` | Search + recently updated articles |
|
||||
| `/wiki/<slug>` | Rendered article with table of contents |
|
||||
| `/wiki/<slug>/edit` | Markdown editor with live preview |
|
||||
| `/new` | Create a new article |
|
||||
|
||||
## Markdown + LaTeX
|
||||
|
||||
Articles support GitHub-ish Markdown (headings, tables, lists, blockquotes, fenced
|
||||
code with highlighting) plus LaTeX: `$E = mc^2$` inline and `$$ ... $$` in display
|
||||
mode. Rendered server-side with `markdown-it` + `markdown-it-texmath` + KaTeX and
|
||||
sanitized with DOMPurify (raw HTML in articles is escaped).
|
||||
|
||||
Handy macros: `\R`, `\N`, `\Z`, `\Q`, `\C` for the number sets.
|
||||
|
||||
## API
|
||||
|
||||
| Method | Endpoint |
|
||||
| --- | --- |
|
||||
| GET | `/api/articles?q=&tag=` — search / filter, no content body |
|
||||
| GET | `/api/articles/slug/:slug` — one article |
|
||||
| POST | `/api/articles` — create (`title` required; slug auto-generated & uniquified) |
|
||||
| PUT | `/api/articles/slug/:slug` — update |
|
||||
| DELETE | `/api/articles/slug/:slug` — delete |
|
||||
|
||||
## Configuration
|
||||
|
||||
| Where | Variable | Default | Meaning |
|
||||
| --- | --- | --- | --- |
|
||||
| `backend/.env` | `PORT` | `5000` | API port |
|
||||
| `backend/.env` | `MONGO_URI` | `mongodb://127.0.0.1:27017/mathew` | Mongo connection |
|
||||
| `frontend` env | `NUXT_PUBLIC_API_BASE` | `http://localhost:5000` | Where the UI calls the API |
|
||||
|
||||
## Editing tips
|
||||
|
||||
- `/` focuses the search box on the home page; `Ctrl/Cmd+S` saves in the editor.
|
||||
- The editor has Write / Split / Preview modes; LaTeX and code highlight update live.
|
||||
- Changing an article's title may change its slug (old links 404 — redirect not implemented).
|
||||
34
frontend/app/app.vue
Normal file
34
frontend/app/app.vue
Normal file
@@ -0,0 +1,34 @@
|
||||
<script setup lang="ts">
|
||||
/* The document language and the fallback title follow the interface locale:
|
||||
the callback form of useHead re-runs them whenever the locale changes. */
|
||||
const { t } = useI18n()
|
||||
const { locale } = useAppLocale()
|
||||
|
||||
useHead(() => ({
|
||||
htmlAttrs: { lang: locale.value },
|
||||
titleTemplate: (title?: string | null) => (title ? `${title} · Mathew` : t('app.title')),
|
||||
}))
|
||||
|
||||
/* keep the book's stack of open pages in step with the route */
|
||||
useArticleTabsSync()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="app-shell">
|
||||
<NuxtRouteAnnouncer />
|
||||
<AppHeader />
|
||||
<main class="app-main">
|
||||
<div class="container">
|
||||
<NuxtPage />
|
||||
</div>
|
||||
</main>
|
||||
<!-- after the page: the article route has put its article on the shelf
|
||||
by the time the book is rendered, so the page in view arrives with
|
||||
its text already written out -->
|
||||
<ArticleBookStack />
|
||||
<SearchModal />
|
||||
<SettingsModal />
|
||||
<ProfileModal />
|
||||
<AuthModal />
|
||||
</div>
|
||||
</template>
|
||||
78
frontend/app/assets/css/_admin.scss
Normal file
78
frontend/app/assets/css/_admin.scss
Normal file
@@ -0,0 +1,78 @@
|
||||
// ---------- Admin dashboard: the list of accounts ----------
|
||||
// One row per account, read left to right: who, what they may do, when they
|
||||
// arrived, and the one thing an admin can change about them.
|
||||
.account-list {
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
.account-entry {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
flex-wrap: wrap;
|
||||
padding: 12px 16px;
|
||||
border-radius: 14px;
|
||||
border: 1px solid var(--border);
|
||||
background: var(--surface);
|
||||
box-shadow: var(--shadow-sm);
|
||||
}
|
||||
|
||||
.account-entry-name {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
font-size: 0.95rem;
|
||||
font-weight: 650;
|
||||
letter-spacing: -0.01em;
|
||||
color: var(--text);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
// the marker on the row that is the person looking at the page
|
||||
.account-entry-you {
|
||||
margin-left: 6px;
|
||||
font-size: 0.72rem;
|
||||
font-weight: 600;
|
||||
color: var(--faint);
|
||||
}
|
||||
|
||||
.account-entry-since { flex-shrink: 0; font-size: 0.78rem; color: var(--faint); }
|
||||
|
||||
// where the ⋮ goes on the row of the admin looking at the page: their own role
|
||||
// and their own account are the two things they cannot change, so the row says
|
||||
// it instead of offering a menu that could only fail
|
||||
.account-entry-note {
|
||||
margin-left: auto;
|
||||
flex-shrink: 0;
|
||||
font-size: 0.76rem;
|
||||
font-style: italic;
|
||||
color: var(--faint);
|
||||
}
|
||||
|
||||
.role-pill {
|
||||
flex-shrink: 0;
|
||||
padding: 3px 11px;
|
||||
border-radius: 999px;
|
||||
background: var(--surface-2);
|
||||
color: var(--muted);
|
||||
font-size: 0.75rem;
|
||||
font-weight: 700;
|
||||
|
||||
// an admin's row is the accent one, so the few of them stand out at a glance
|
||||
&.is-admin {
|
||||
background: color-mix(in srgb, var(--accent) 14%, transparent);
|
||||
color: var(--accent);
|
||||
}
|
||||
}
|
||||
|
||||
// on a wide row the ⋮ sits at the end of the line; once the row wraps (a narrow
|
||||
// window) it starts a line of its own, still at the end of what came before
|
||||
.account-entry-kebab { margin-left: auto; flex: none; }
|
||||
|
||||
// the article cards' skeleton, in the shape of one row of the list
|
||||
.skeleton-row { height: 62px; }
|
||||
225
frontend/app/assets/css/_article.scss
Normal file
225
frontend/app/assets/css/_article.scss
Normal file
@@ -0,0 +1,225 @@
|
||||
@use 'mixins' as *;
|
||||
|
||||
// ---------- Article page ----------
|
||||
.article-page { padding-block: 40px 80px; }
|
||||
|
||||
.article-head { margin-bottom: 8px; }
|
||||
|
||||
.article-eyebrow {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
font-size: 0.8rem;
|
||||
color: var(--faint);
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
// the title and the ⋮ share one line: the title takes what is left and wraps
|
||||
// its own text, the actions keep their place at the side of it
|
||||
.article-title-row {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.article-title {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
margin: 0;
|
||||
font-size: clamp(1.9rem, 4vw, 2.6rem);
|
||||
font-weight: 830;
|
||||
letter-spacing: -0.03em;
|
||||
line-height: 1.15;
|
||||
}
|
||||
|
||||
.article-actions {
|
||||
flex: none;
|
||||
display: flex;
|
||||
gap: 9px;
|
||||
padding-top: 10px;
|
||||
}
|
||||
|
||||
// The ⋮ menu: the quiet button that folds several actions into one place. The
|
||||
// article's title row uses it for Edit, languages and Delete; the admin
|
||||
// dashboard uses it for the role and the account itself.
|
||||
.kebab { position: relative; }
|
||||
|
||||
.kebab-toggle {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 34px;
|
||||
height: 34px;
|
||||
border-radius: 9px;
|
||||
border: 1px solid var(--border);
|
||||
background: var(--surface);
|
||||
color: var(--muted);
|
||||
transition: background-color 0.15s, border-color 0.15s, color 0.15s;
|
||||
|
||||
&:hover,
|
||||
&.open {
|
||||
border-color: var(--border-strong);
|
||||
background: var(--surface-2);
|
||||
color: var(--text);
|
||||
}
|
||||
}
|
||||
|
||||
.kebab-dropdown {
|
||||
@include dropdown-panel($z: 30, $overflow: visible);
|
||||
right: 0;
|
||||
min-width: 190px;
|
||||
text-align: left;
|
||||
|
||||
// the language menu rides inside as a row of the ⋮ menu — flat, full-width,
|
||||
// its own list dropping over the rows below
|
||||
.lang-menu {
|
||||
width: 100%;
|
||||
|
||||
> .btn {
|
||||
justify-content: flex-start;
|
||||
width: 100%;
|
||||
padding: 8px 10px;
|
||||
border: 0;
|
||||
border-radius: 8px;
|
||||
background: none;
|
||||
color: var(--text);
|
||||
font-size: 0.85rem;
|
||||
font-weight: 600;
|
||||
|
||||
&:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.kebab-item {
|
||||
@include menu-row(8px 10px, 9px);
|
||||
text-decoration: none;
|
||||
|
||||
svg { flex: none; color: var(--faint); transition: color 0.12s; }
|
||||
|
||||
// a menu row whose request is still in flight: readable, but no longer a way
|
||||
// to ask twice
|
||||
&:disabled {
|
||||
color: var(--faint);
|
||||
cursor: default;
|
||||
background: none;
|
||||
|
||||
svg { color: var(--faint); }
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background: color-mix(in srgb, var(--accent) 12%, transparent);
|
||||
|
||||
svg { color: var(--accent); }
|
||||
}
|
||||
}
|
||||
|
||||
.kebab-danger:hover {
|
||||
background: color-mix(in srgb, var(--danger) 12%, transparent);
|
||||
|
||||
svg { color: var(--danger); }
|
||||
}
|
||||
|
||||
.kebab-sep { margin: 5px 0; border-top: 1px solid var(--border); }
|
||||
|
||||
// Topics line at the foot of an article: “Topics: Probability, Calculus”.
|
||||
// The comma joins the topics; a break stays tidy after it.
|
||||
.article-topics {
|
||||
margin-top: 36px;
|
||||
padding-top: 14px;
|
||||
border-top: 1px solid var(--border);
|
||||
font-size: 0.85rem;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.article-topics-label { font-weight: 600; margin-right: 0.35em; }
|
||||
|
||||
.article-topics .topic-link {
|
||||
color: var(--accent);
|
||||
text-decoration: none;
|
||||
margin-right: 0.5em;
|
||||
|
||||
&:not(:last-child)::after { content: ','; }
|
||||
|
||||
&:hover { text-decoration: underline; }
|
||||
}
|
||||
|
||||
.article-body {
|
||||
margin-top: 34px;
|
||||
border-top: 1px solid var(--border);
|
||||
padding-top: 8px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
// TOC
|
||||
.toc {
|
||||
position: sticky;
|
||||
top: 24px;
|
||||
font-size: 0.855rem;
|
||||
|
||||
@media (max-width: 1024px) {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.toc-title { @include eyebrow; margin-bottom: 10px; }
|
||||
|
||||
.toc ol {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border-left: 2px solid var(--border);
|
||||
}
|
||||
|
||||
.toc li a {
|
||||
display: block;
|
||||
padding: 5px 0 5px 14px;
|
||||
margin-left: -2px;
|
||||
border-left: 2px solid transparent;
|
||||
color: var(--muted);
|
||||
text-decoration: none;
|
||||
line-height: 1.4;
|
||||
transition: color 0.15s, border-color 0.15s;
|
||||
|
||||
&:hover { color: var(--text); }
|
||||
|
||||
&.active { color: var(--accent); border-left-color: var(--accent); }
|
||||
}
|
||||
|
||||
.toc li.level-3 a { padding-left: 28px; font-size: 0.8rem; }
|
||||
|
||||
// Recently viewed (article sidebar)
|
||||
.recently-viewed {
|
||||
margin-top: 26px;
|
||||
padding-top: 18px;
|
||||
border-top: 1px solid var(--border);
|
||||
font-size: 0.855rem;
|
||||
|
||||
ul { list-style: none; margin: 0; padding: 0; }
|
||||
|
||||
li {
|
||||
+ li { margin-top: 2px; }
|
||||
|
||||
a {
|
||||
display: block;
|
||||
padding: 6px 9px;
|
||||
border-radius: 7px;
|
||||
color: var(--muted);
|
||||
text-decoration: none;
|
||||
line-height: 1.35;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
transition: background 0.15s, color 0.15s;
|
||||
|
||||
&:hover {
|
||||
background: color-mix(in srgb, var(--accent) 8%, var(--bg-elev));
|
||||
color: var(--text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.rv-title { @include eyebrow; margin-bottom: 8px; }
|
||||
67
frontend/app/assets/css/_articles.scss
Normal file
67
frontend/app/assets/css/_articles.scss
Normal file
@@ -0,0 +1,67 @@
|
||||
@use 'mixins' as *;
|
||||
|
||||
// ---------- Articles index ----------
|
||||
.topic-tally { font-size: 0.85rem; color: var(--muted); }
|
||||
|
||||
.topic-dropdown {
|
||||
@include dropdown-panel;
|
||||
left: 0;
|
||||
right: 0;
|
||||
max-height: 280px;
|
||||
}
|
||||
|
||||
.topic-option {
|
||||
@include menu-row(8px 12px, 12px, 0.88rem);
|
||||
justify-content: space-between;
|
||||
text-align: left;
|
||||
|
||||
&:hover, &.active { background: color-mix(in srgb, var(--accent) 12%, transparent); }
|
||||
}
|
||||
|
||||
.topic-dropdown-none {
|
||||
padding: 8px 12px;
|
||||
margin: 0;
|
||||
font-size: 0.85rem;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.topic-search-wrap {
|
||||
position: relative;
|
||||
margin-bottom: 14px;
|
||||
|
||||
svg {
|
||||
position: absolute;
|
||||
left: 14px;
|
||||
top: 50%;
|
||||
translate: 0 -50%;
|
||||
color: var(--faint);
|
||||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
|
||||
.topic-search {
|
||||
width: 100%;
|
||||
height: 40px;
|
||||
padding: 0 14px 0 40px;
|
||||
border-radius: 12px;
|
||||
border: 1px solid var(--border);
|
||||
background: var(--surface);
|
||||
box-shadow: var(--shadow-sm);
|
||||
font-size: 0.9rem;
|
||||
transition: border-color 0.15s, box-shadow 0.2s;
|
||||
|
||||
&:focus {
|
||||
outline: none;
|
||||
border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
|
||||
box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent);
|
||||
}
|
||||
}
|
||||
|
||||
.topic-count {
|
||||
padding: 1px 7px;
|
||||
border-radius: 999px;
|
||||
background: color-mix(in srgb, var(--accent) 14%, transparent);
|
||||
color: var(--accent);
|
||||
font-size: 0.72rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
119
frontend/app/assets/css/_auth.scss
Normal file
119
frontend/app/assets/css/_auth.scss
Normal file
@@ -0,0 +1,119 @@
|
||||
@use 'mixins' as *;
|
||||
|
||||
// ---------- Sign in ----------
|
||||
// Anyone may read Mathew; writing it takes an account. The gate is what a
|
||||
// signed-out visitor of the editor finds in the form's place (AuthGate.vue), and
|
||||
// the popup is the way in from anywhere (AuthModal.vue). The popup sits above the
|
||||
// fullscreen editor (1000) and its own popups (1100, 1150): a save that comes
|
||||
// back refusing an expired session has to be answered where the editor already
|
||||
// fills the screen.
|
||||
.auth-overlay { @include overlay(1160); }
|
||||
|
||||
.auth-modal {
|
||||
@include sheet(420px);
|
||||
|
||||
&:focus, &:focus-visible { outline: none; }
|
||||
}
|
||||
|
||||
.auth-modal-head { @include sheet-head; }
|
||||
|
||||
.auth-title { @include sheet-title; }
|
||||
|
||||
.auth-modal-body { padding: 18px; }
|
||||
|
||||
// the two ways in, side by side
|
||||
.auth-tabs { @include segmented; margin-bottom: 18px; }
|
||||
|
||||
.auth-tab { @include segmented-tab(7px 14px, 0.84rem); }
|
||||
|
||||
// why the popup turned up on its own — a session that expired mid-draft
|
||||
.auth-notice {
|
||||
margin: -6px 0 16px;
|
||||
padding: 10px 12px;
|
||||
border: 1px solid color-mix(in srgb, var(--danger) 30%, var(--border));
|
||||
border-radius: 10px;
|
||||
background: color-mix(in srgb, var(--danger) 7%, var(--surface));
|
||||
color: var(--muted);
|
||||
font-size: 0.84rem;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.auth-modal .field input {
|
||||
width: 100%;
|
||||
padding: 12px 14px;
|
||||
border-radius: 11px;
|
||||
border: 1px solid var(--border);
|
||||
background: var(--bg-elev);
|
||||
}
|
||||
|
||||
.auth-submit { width: 100%; margin-top: 2px; }
|
||||
|
||||
.auth-switch {
|
||||
margin: 16px 0 0;
|
||||
text-align: center;
|
||||
font-size: 0.84rem;
|
||||
color: var(--muted);
|
||||
|
||||
button {
|
||||
color: var(--accent);
|
||||
font-weight: 650;
|
||||
|
||||
&:hover { text-decoration: underline; }
|
||||
}
|
||||
}
|
||||
|
||||
@include popup-anim(
|
||||
'auth-popup',
|
||||
'.auth-modal',
|
||||
0.16s,
|
||||
transform 0.2s cubic-bezier(0.22, 0.61, 0.36, 1),
|
||||
-10px
|
||||
);
|
||||
|
||||
// the editor's stand-in until there is a session
|
||||
.auth-gate {
|
||||
max-width: 480px;
|
||||
margin: clamp(36px, 8vh, 92px) auto;
|
||||
padding: 34px 30px 30px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 18px;
|
||||
background: var(--bg-elev);
|
||||
box-shadow: var(--shadow-lg);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.auth-gate-mark {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
width: 46px;
|
||||
height: 46px;
|
||||
margin: 0 auto 16px;
|
||||
border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--border));
|
||||
border-radius: 50%;
|
||||
background: color-mix(in srgb, var(--accent) 10%, transparent);
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
.auth-gate-title {
|
||||
margin: 0 0 8px;
|
||||
font-size: 1.3rem;
|
||||
letter-spacing: -0.01em;
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
.auth-gate-text {
|
||||
max-width: 38ch;
|
||||
margin: 0 auto 22px;
|
||||
color: var(--muted);
|
||||
font-size: 0.93rem;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.auth-gate-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.auth-gate-fine { margin: 18px 0 0; font-size: 0.8rem; color: var(--faint); }
|
||||
65
frontend/app/assets/css/_base.scss
Normal file
65
frontend/app/assets/css/_base.scss
Normal file
@@ -0,0 +1,65 @@
|
||||
// ---------- Base ----------
|
||||
*, *::before, *::after { box-sizing: border-box; }
|
||||
|
||||
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
font-family:
|
||||
'Computer Modern',
|
||||
'CMU Serif',
|
||||
Georgia,
|
||||
'Times New Roman',
|
||||
serif;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
line-height: 1.6;
|
||||
transition: background-color 0.25s ease, color 0.25s ease;
|
||||
}
|
||||
|
||||
::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); }
|
||||
|
||||
a { color: var(--accent); }
|
||||
|
||||
button {
|
||||
font: inherit;
|
||||
color: inherit;
|
||||
background: none;
|
||||
border: 0;
|
||||
padding: 0;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
input, textarea, select { font: inherit; color: inherit; }
|
||||
|
||||
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 8px; }
|
||||
|
||||
.container {
|
||||
width: 100%;
|
||||
max-width: 1160px;
|
||||
margin-inline: auto;
|
||||
padding-inline: clamp(16px, 4vw, 32px);
|
||||
}
|
||||
|
||||
.mono,
|
||||
code,
|
||||
pre,
|
||||
textarea.md-input {
|
||||
font-family: ui-monospace, 'JetBrains Mono', 'Cascadia Code', 'Fira Code',
|
||||
Menlo, Consolas, monospace;
|
||||
}
|
||||
|
||||
// ---------- Scrollbars (subtle, webkit) ----------
|
||||
::-webkit-scrollbar { width: 11px; height: 10px; }
|
||||
|
||||
::-webkit-scrollbar-thumb {
|
||||
background: color-mix(in srgb, var(--text) 18%, transparent);
|
||||
border-radius: 8px;
|
||||
border: 3px solid transparent;
|
||||
background-clip: content-box;
|
||||
|
||||
&:hover {
|
||||
background: color-mix(in srgb, var(--text) 30%, transparent);
|
||||
background-clip: content-box;
|
||||
}
|
||||
}
|
||||
300
frontend/app/assets/css/_book.scss
Normal file
300
frontend/app/assets/css/_book.scss
Normal file
@@ -0,0 +1,300 @@
|
||||
@use 'mixins' as *;
|
||||
|
||||
// ---------- Reader: an open book of article pages ----------
|
||||
// Every article opened in this session is a page, laid out beside the last
|
||||
// in a track you move along sideways (ArticleBookStack.vue). Pages are solid
|
||||
// paper, and each sticks a spine's width further from the left edge than the
|
||||
// one before it — left: calc(var(--i) * var(--spine-w)) — so turning to a
|
||||
// newer page slides it over the older ones, which park along the edge with
|
||||
// nothing but their spines showing: a stack of pages, titled along the edge
|
||||
// like books on a shelf. A page is as wide as its share of the reading
|
||||
// surface — minus the spines of every other page, but never more than a
|
||||
// comfortable measure, and open across the whole desk when it is the only
|
||||
// page in the book — so on a wide desk the next page waits fully in view
|
||||
// beside the one you read, not only its spine; on a narrow one the rest wait
|
||||
// out at the right edge. A spine the desk has no room for is copied to that
|
||||
// edge — the dock, .book-dock below — so no page is ever more than a click
|
||||
// away, though its own spine is off the end of the row. Click a spine to turn
|
||||
// back to that page, the × to take it out of the book. Below 900px the book
|
||||
// folds to the one page in view and its neighbours become chips along the
|
||||
// top. Routes stay the source of truth — every page is a plain /wiki/<slug>
|
||||
// URL, and useArticleTabs keeps the stack. (The --sidebar-w, --spine-w and
|
||||
// --pane-max-w tokens live in _tokens.scss.)
|
||||
|
||||
// the surface the book lies open on
|
||||
.book-layer {
|
||||
position: fixed;
|
||||
inset: 0 0 0 var(--sidebar-w);
|
||||
transition: left 0.22s ease;
|
||||
z-index: 70;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background: var(--bg-elev);
|
||||
box-shadow: -10px 0 26px rgb(5 7 13 / 9%);
|
||||
}
|
||||
|
||||
// nothing lives at this URL: the route host says so over the open book
|
||||
.reader-note {
|
||||
position: fixed;
|
||||
inset: 0 0 0 var(--sidebar-w);
|
||||
transition: left 0.22s ease;
|
||||
z-index: 74;
|
||||
background: var(--bg-elev);
|
||||
box-shadow: -10px 0 26px rgb(5 7 13 / 4%);
|
||||
}
|
||||
|
||||
// the row of pages, moved along sideways
|
||||
.book-track {
|
||||
--pane-w: calc(100% - (var(--panes, 1) - 1) * var(--spine-w));
|
||||
position: relative;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
align-items: stretch;
|
||||
overflow-x: auto;
|
||||
overflow-y: hidden;
|
||||
overscroll-behavior: contain;
|
||||
// the desk under the pages: once a page stops short of the reading
|
||||
// surface, what's left of the desk shows beside it
|
||||
background: var(--bg);
|
||||
@include no-scrollbar;
|
||||
}
|
||||
|
||||
// one page: solid paper, parked beside the pages under it
|
||||
.book-pane {
|
||||
position: sticky;
|
||||
left: calc(var(--i) * var(--spine-w));
|
||||
z-index: calc(var(--i) + 1);
|
||||
flex: 0 0 var(--pane-w);
|
||||
// A page takes every inch of the reading surface it can — the one in view
|
||||
// opens across the whole desk, not just a column of it. Only once so many
|
||||
// are open that each page's share falls below a comfortable reading width
|
||||
// does it hold at that width and the book scroll sideways instead.
|
||||
min-width: min(46rem, 100%);
|
||||
// ...and on a desk wide enough for it to stretch past a page of paper, it
|
||||
// holds at --pane-max-w and leaves the rest of the desk bare. The single
|
||||
// page of a one-page book is exempt below.
|
||||
max-width: var(--pane-max-w);
|
||||
display: flex;
|
||||
background: var(--bg-elev);
|
||||
// the fore-edge of the paper, against the desk and the next page
|
||||
border-right: 1px solid var(--border);
|
||||
// the edge of this page lying on top of the ones beneath it
|
||||
box-shadow: -10px 0 22px rgb(5 7 13 / 7%);
|
||||
animation: page-turned-in 0.3s cubic-bezier(0.22, 0.8, 0.36, 1) both;
|
||||
}
|
||||
|
||||
// a book with a single page in it lies open across the whole desk: there is
|
||||
// no other page waiting for that space, so the page takes all of it
|
||||
.book-pane:only-child { max-width: none; }
|
||||
|
||||
// a page that isn't in view asks to be turned to: the whole of it is
|
||||
// clickable (clicks on its inert body retarget to the pane itself), not
|
||||
// just the spine
|
||||
.book-pane:not(.active) {
|
||||
cursor: pointer;
|
||||
|
||||
.pane-body, .pane-body * { cursor: pointer; }
|
||||
}
|
||||
|
||||
// a new page is laid down at the right and eased into the stack
|
||||
@keyframes page-turned-in {
|
||||
from { transform: translateX(56px); opacity: 0; }
|
||||
}
|
||||
|
||||
// the page's fore-edge: its title standing on end, and the × that closes it.
|
||||
// Once a newer page is turned over this one, the spine is all that's left in
|
||||
// sight — so it is the handle for turning back. A page whose spine is off the
|
||||
// edge of the desk has it copied at the edge itself, in the dock below, which
|
||||
// borrows .spine-title and .spine-close as its own standing type.
|
||||
.pane-spine {
|
||||
flex: 0 0 var(--spine-w);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 6px 0 10px;
|
||||
background: var(--surface);
|
||||
border-right: 1px solid var(--border);
|
||||
color: var(--muted);
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
transition: color 0.15s, background-color 0.15s;
|
||||
|
||||
&:hover { color: var(--text); background: var(--surface-2); }
|
||||
}
|
||||
|
||||
// the page in view has its spine marked, the way a ribbon marks a book
|
||||
.book-pane.active .pane-spine {
|
||||
color: var(--accent);
|
||||
background: color-mix(in srgb, var(--accent) 10%, var(--surface));
|
||||
}
|
||||
|
||||
.spine-close {
|
||||
@include icon-target(15px, 5px);
|
||||
color: var(--faint);
|
||||
transition: color 0.15s, background-color 0.15s;
|
||||
@include close-target;
|
||||
|
||||
svg { display: block; }
|
||||
}
|
||||
|
||||
.spine-title {
|
||||
writing-mode: vertical-rl;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
font-size: 0.78rem;
|
||||
font-weight: 700;
|
||||
line-height: 1.35;
|
||||
letter-spacing: 0.01em;
|
||||
padding-top: 0;
|
||||
}
|
||||
|
||||
// the page itself: the article, scrolling on its own
|
||||
.pane-body {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.pane-scroll {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
overscroll-behavior: contain;
|
||||
padding-inline: clamp(16px, 3.5vw, 36px);
|
||||
|
||||
// the article takes the page as a single centered column
|
||||
.article-page { max-width: 78ch; margin-inline: auto; }
|
||||
}
|
||||
|
||||
.pane-skeleton { padding-top: 32px; }
|
||||
|
||||
// folded up narrow: the neighbours of the page in view, as chips along the
|
||||
// top. Wide screens read the spines instead.
|
||||
.book-chips {
|
||||
display: none;
|
||||
flex-shrink: 0;
|
||||
gap: 8px;
|
||||
padding: 9px 10px;
|
||||
overflow-x: auto;
|
||||
overscroll-behavior: contain;
|
||||
background: var(--surface);
|
||||
border-bottom: 1px solid var(--border);
|
||||
@include no-scrollbar;
|
||||
}
|
||||
|
||||
.book-chip {
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
max-width: 46vw;
|
||||
padding: 5px 7px 5px 11px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 999px;
|
||||
background: var(--surface-2);
|
||||
color: var(--muted);
|
||||
font-size: 0.79rem;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
transition: color 0.15s, background-color 0.15s, border-color 0.15s;
|
||||
|
||||
&:hover { color: var(--text); }
|
||||
|
||||
&.active {
|
||||
color: var(--accent);
|
||||
background: var(--bg-elev);
|
||||
border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
|
||||
}
|
||||
}
|
||||
|
||||
.chip-title {
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.chip-close { @include icon-target(16px, 5px); color: var(--faint); @include close-target; }
|
||||
|
||||
// ---------- The dock: pages waiting beyond the right edge of the desk -----
|
||||
// A page further along the book than the one in view lies somewhere off the
|
||||
// right edge of the desk, reachable by dragging the row sideways. While it is
|
||||
// out there, its spine is kept at the edge itself: a stack one spine wide, in
|
||||
// the order the pages were opened, each one the standing title and × of the
|
||||
// page it stands for. Click it and the book turns to that page as though you
|
||||
// had scrolled to it; the page's own spine comes into view and its copy in the
|
||||
// dock goes away (ArticleBookStack measures which pages are out there). It
|
||||
// rides above every page of the book — the pages are numbered one apiece by
|
||||
// --panes — and, being inside the reading surface, below anything popped over
|
||||
// it.
|
||||
.book-dock {
|
||||
position: absolute;
|
||||
inset-block: 0;
|
||||
right: 0;
|
||||
z-index: calc(var(--panes, 1) + 2);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: var(--spine-w);
|
||||
padding: 6px 0;
|
||||
background: var(--surface);
|
||||
border-left: 1px solid var(--border);
|
||||
box-shadow: -10px 0 22px rgb(5 7 13 / 7%);
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
// the waiting spines share the height of the desk, so however many pages are
|
||||
// out there every one of them keeps a place at the edge, its title cut short
|
||||
// to fit — the whole title is in the tooltip
|
||||
.dock-spine {
|
||||
flex: 1 1 0;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 4px 0;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
transition: color 0.15s, background-color 0.15s;
|
||||
|
||||
+ .dock-spine { border-top: 1px solid var(--border); }
|
||||
|
||||
&:hover { color: var(--text); background: var(--surface-2); }
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.book-layer, .reader-note { inset: 0; box-shadow: none; }
|
||||
|
||||
.book-track { overflow-x: hidden; }
|
||||
|
||||
// folded: only the page in view is out, the rest are chips along the top
|
||||
.book-pane {
|
||||
position: static;
|
||||
flex: 1 1 100%;
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
max-width: 100%;
|
||||
box-shadow: none;
|
||||
|
||||
&:not(.active) { display: none; }
|
||||
}
|
||||
|
||||
.book-chips { display: flex; }
|
||||
|
||||
// folded, the book has no edges to stack spines against: the chips along
|
||||
// the top are every page of it
|
||||
.book-dock { display: none; }
|
||||
|
||||
.pane-scroll { padding-inline: 16px; }
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.book-pane { animation: none; }
|
||||
}
|
||||
62
frontend/app/assets/css/_buttons.scss
Normal file
62
frontend/app/assets/css/_buttons.scss
Normal file
@@ -0,0 +1,62 @@
|
||||
// ---------- Buttons ----------
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
padding: 10px 18px;
|
||||
border-radius: 10px;
|
||||
border: 1px solid transparent;
|
||||
font-size: 0.9rem;
|
||||
font-weight: 650;
|
||||
text-decoration: none;
|
||||
white-space: nowrap;
|
||||
transition: filter 0.15s, background-color 0.15s, border-color 0.15s, transform 0.1s,
|
||||
box-shadow 0.15s;
|
||||
|
||||
&:active { transform: translateY(1px); }
|
||||
|
||||
&[disabled] { opacity: 0.55; pointer-events: none; }
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 55%, var(--accent-2)));
|
||||
color: #fff;
|
||||
box-shadow: 0 6px 18px -6px color-mix(in srgb, var(--accent) 65%, transparent);
|
||||
|
||||
&:hover { filter: brightness(1.1); }
|
||||
}
|
||||
|
||||
.btn-ghost {
|
||||
border-color: var(--border);
|
||||
background: var(--surface);
|
||||
color: var(--text);
|
||||
|
||||
&:hover { border-color: var(--border-strong); background: var(--surface-2); }
|
||||
}
|
||||
|
||||
.btn-danger {
|
||||
border-color: color-mix(in srgb, var(--danger) 45%, transparent);
|
||||
color: var(--danger);
|
||||
background: transparent;
|
||||
|
||||
&:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }
|
||||
}
|
||||
|
||||
.btn-sm { padding: 7px 13px; font-size: 0.82rem; border-radius: 8px; }
|
||||
|
||||
.icon-btn {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
width: 38px;
|
||||
height: 38px;
|
||||
border-radius: 10px;
|
||||
border: 1px solid var(--border);
|
||||
background: var(--surface);
|
||||
color: var(--muted);
|
||||
transition: color 0.15s, border-color 0.15s, transform 0.15s;
|
||||
|
||||
&:hover { color: var(--text); border-color: var(--border-strong); }
|
||||
|
||||
&:active { transform: scale(0.94); }
|
||||
}
|
||||
80
frontend/app/assets/css/_cards.scss
Normal file
80
frontend/app/assets/css/_cards.scss
Normal file
@@ -0,0 +1,80 @@
|
||||
// ---------- Article cards ----------
|
||||
.section { position: relative; padding-bottom: clamp(56px, 9vh, 96px); }
|
||||
|
||||
.articles-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.article-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
padding: 22px;
|
||||
border-radius: 16px;
|
||||
border: 1px solid var(--border);
|
||||
background: var(--surface);
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
box-shadow: var(--shadow-sm);
|
||||
transition: transform 0.18s ease, border-color 0.18s, box-shadow 0.18s;
|
||||
|
||||
&:hover {
|
||||
transform: translateY(-3px);
|
||||
border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
|
||||
box-shadow: var(--shadow-lg);
|
||||
}
|
||||
|
||||
&:focus-visible { box-shadow: var(--ring); }
|
||||
}
|
||||
|
||||
.card-top {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.card-kicker {
|
||||
font-size: 0.72rem;
|
||||
font-weight: 700;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.08em;
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
.card-title {
|
||||
margin: 0;
|
||||
font-size: 1.14rem;
|
||||
font-weight: 720;
|
||||
letter-spacing: -0.015em;
|
||||
line-height: 1.3;
|
||||
}
|
||||
|
||||
.card-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
margin-top: 4px;
|
||||
font-size: 0.78rem;
|
||||
color: var(--faint);
|
||||
}
|
||||
|
||||
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
|
||||
|
||||
.tag {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 3px 10px;
|
||||
border-radius: 999px;
|
||||
background: color-mix(in srgb, var(--accent) 11%, transparent);
|
||||
color: var(--accent);
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
text-decoration: none;
|
||||
transition: background-color 0.15s;
|
||||
}
|
||||
|
||||
a.tag:hover { background: color-mix(in srgb, var(--accent) 22%, transparent); }
|
||||
295
frontend/app/assets/css/_editor.scss
Normal file
295
frontend/app/assets/css/_editor.scss
Normal file
@@ -0,0 +1,295 @@
|
||||
@use 'mixins' as *;
|
||||
|
||||
// ---------- Editor ----------
|
||||
.editor-page { padding-block: 36px 90px; max-width: 1080px; }
|
||||
|
||||
.editor-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 14px;
|
||||
flex-wrap: wrap;
|
||||
margin-bottom: 24px;
|
||||
|
||||
h1 {
|
||||
margin: 0;
|
||||
font-size: 1.5rem;
|
||||
letter-spacing: -0.025em;
|
||||
font-weight: 800;
|
||||
}
|
||||
}
|
||||
|
||||
.editor-head-actions { display: flex; gap: 10px; align-items: center; }
|
||||
|
||||
.field {
|
||||
margin-bottom: 18px;
|
||||
|
||||
label {
|
||||
display: block;
|
||||
font-size: 0.8rem;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.03em;
|
||||
text-transform: uppercase;
|
||||
color: var(--muted);
|
||||
margin-bottom: 7px;
|
||||
}
|
||||
|
||||
.hint {
|
||||
text-transform: none;
|
||||
font-weight: 500;
|
||||
letter-spacing: 0;
|
||||
color: var(--faint);
|
||||
}
|
||||
|
||||
input[type='text'],
|
||||
select {
|
||||
width: 100%;
|
||||
padding: 12px 14px;
|
||||
border-radius: 11px;
|
||||
border: 1px solid var(--border);
|
||||
background: var(--bg-elev);
|
||||
transition: border-color 0.15s, box-shadow 0.2s;
|
||||
}
|
||||
|
||||
// `input:focus` (not just the styled types) so every field input —
|
||||
// the sign-in popup's password among them — gets the same ring
|
||||
input:focus,
|
||||
select:focus {
|
||||
outline: none;
|
||||
border-color: var(--accent);
|
||||
box-shadow: var(--ring);
|
||||
}
|
||||
|
||||
input.title-input {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 720;
|
||||
letter-spacing: -0.02em;
|
||||
padding: 14px 16px;
|
||||
}
|
||||
|
||||
select { cursor: pointer; }
|
||||
}
|
||||
|
||||
.field-row {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 16px;
|
||||
|
||||
@media (max-width: 640px) {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
.slug-preview {
|
||||
font-size: 0.8rem;
|
||||
color: var(--faint);
|
||||
margin-top: 6px;
|
||||
|
||||
code { color: var(--accent); }
|
||||
}
|
||||
|
||||
// editor body
|
||||
.editor-body {
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 15px;
|
||||
background: var(--bg-elev);
|
||||
overflow: hidden;
|
||||
box-shadow: var(--shadow-sm);
|
||||
}
|
||||
|
||||
.editor-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
padding: 9px 11px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
background: var(--surface);
|
||||
}
|
||||
|
||||
.mode-btn {
|
||||
padding: 7px 14px;
|
||||
border-radius: 8px;
|
||||
font-size: 0.85rem;
|
||||
font-weight: 620;
|
||||
color: var(--muted);
|
||||
transition: background-color 0.15s, color 0.15s;
|
||||
|
||||
&:hover { color: var(--text); }
|
||||
|
||||
&.active {
|
||||
background: var(--surface-2);
|
||||
color: var(--text);
|
||||
box-shadow: inset 0 0 0 1px var(--border);
|
||||
}
|
||||
}
|
||||
|
||||
.toolbar-actions {
|
||||
margin-left: auto;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.toolbar-icon-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 7px 9px;
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
.editor-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
|
||||
&.mode-write {
|
||||
grid-template-columns: 1fr;
|
||||
|
||||
.preview-pane { display: none; }
|
||||
}
|
||||
|
||||
&.mode-preview {
|
||||
grid-template-columns: 1fr;
|
||||
|
||||
.write-pane { display: none; }
|
||||
}
|
||||
}
|
||||
|
||||
textarea.md-input {
|
||||
display: block;
|
||||
width: 100%;
|
||||
min-height: 480px;
|
||||
padding: 22px;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
resize: vertical;
|
||||
font-size: 0.9rem;
|
||||
line-height: 1.75;
|
||||
tab-size: 2;
|
||||
|
||||
&:focus { outline: none; }
|
||||
|
||||
&::placeholder { color: var(--faint); }
|
||||
}
|
||||
|
||||
.preview-pane {
|
||||
border-left: 1px solid var(--border);
|
||||
padding: 22px 26px;
|
||||
min-width: 0;
|
||||
overflow-wrap: break-word;
|
||||
}
|
||||
|
||||
.preview-label { @include eyebrow; margin-bottom: 14px; }
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.editor-grid { grid-template-columns: 1fr; }
|
||||
|
||||
.preview-pane { border-left: 0 !important; border-top: 1px solid var(--border); }
|
||||
}
|
||||
|
||||
// editor writing-cheatsheet popup — same shape as the settings modal,
|
||||
// but above the fullscreen editor (z-index 1000)
|
||||
.cheatsheet-overlay { @include overlay(1100, clamp(40px, 10vh, 110px)); }
|
||||
|
||||
.cheatsheet-modal { @include sheet(680px, min(620px, calc(100vh - 90px))); }
|
||||
|
||||
.cheatsheet-head { @include sheet-head; }
|
||||
|
||||
.cheatsheet-title { @include sheet-title; }
|
||||
|
||||
.cheatsheet-body {
|
||||
@include sheet-body(20px);
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
|
||||
gap: 24px 28px;
|
||||
align-items: start;
|
||||
}
|
||||
|
||||
.cheatsheet-group-title {
|
||||
@include eyebrow(0.74rem, 750, 0.08em, var(--accent));
|
||||
margin: 0 0 10px;
|
||||
}
|
||||
|
||||
.cheat-row {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 10px;
|
||||
font-size: 0.84rem;
|
||||
color: var(--muted);
|
||||
|
||||
& + & { margin-top: 7px; }
|
||||
|
||||
code {
|
||||
flex: 0 0 auto;
|
||||
padding: 2px 7px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 6px;
|
||||
background: var(--surface-2);
|
||||
color: var(--text);
|
||||
font-size: 0.78rem;
|
||||
}
|
||||
|
||||
.katex { font-size: 1em; }
|
||||
}
|
||||
|
||||
@include popup-anim('cheatsheet-popup', '.cheatsheet-modal', 0.18s, transform 0.18s ease, 10px);
|
||||
|
||||
// discard-changes popup — small sibling of the settings modal, raised above
|
||||
// the fullscreen editor (z-index 1000)
|
||||
.confirm-overlay { @include overlay(1150, clamp(56px, 18vh, 200px)); }
|
||||
|
||||
.confirm-modal {
|
||||
width: min(430px, 100%);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 16px;
|
||||
background: var(--bg-elev);
|
||||
box-shadow: var(--shadow-lg);
|
||||
padding: 22px;
|
||||
}
|
||||
|
||||
.confirm-title { margin: 0; font-size: 1.02rem; font-weight: 700; }
|
||||
|
||||
.confirm-message {
|
||||
margin: 8px 0 0;
|
||||
font-size: 0.88rem;
|
||||
line-height: 1.55;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.confirm-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 10px;
|
||||
margin-top: 22px;
|
||||
}
|
||||
|
||||
@include popup-anim('confirm-popup', '.confirm-modal', 0.18s, transform 0.18s ease, 10px);
|
||||
|
||||
// fullscreen editor
|
||||
.editor-body.is-fullscreen {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 1000;
|
||||
border-radius: 0;
|
||||
border-left: 0;
|
||||
border-right: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.editor-toolbar { flex: 0 0 auto; }
|
||||
|
||||
.editor-grid { flex: 1; min-height: 0; }
|
||||
|
||||
.write-pane, .preview-pane { min-height: 0; overflow-y: auto; }
|
||||
|
||||
textarea.md-input { height: 100%; min-height: 0; resize: none; }
|
||||
}
|
||||
|
||||
// below 900px the split stacks vertically — give each pane half the screen
|
||||
@media (max-width: 900px) {
|
||||
.editor-body.is-fullscreen .editor-grid:not(.mode-write):not(.mode-preview) {
|
||||
grid-template-rows: 1fr 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
.form-error { color: var(--danger); font-size: 0.88rem; margin: 12px 2px 0; }
|
||||
19
frontend/app/assets/css/_fonts.scss
Normal file
19
frontend/app/assets/css/_fonts.scss
Normal file
@@ -0,0 +1,19 @@
|
||||
// ---------- Fonts: Computer Modern (CMU) ----------
|
||||
// CMU ships only two weights, so we map the design's intermediate
|
||||
// weights onto real faces: <=550 → regular, >550 → bold extended.
|
||||
$cmu-faces: (
|
||||
('cmunrm', 100 550, normal),
|
||||
('cmunti', 100 550, italic),
|
||||
('cmunbx', 551 900, normal),
|
||||
('cmunbi', 551 900, italic),
|
||||
);
|
||||
|
||||
@each $file, $weight, $style in $cmu-faces {
|
||||
@font-face {
|
||||
font-family: 'Computer Modern';
|
||||
src: url('/fonts/#{$file}.ttf') format('truetype');
|
||||
font-weight: $weight;
|
||||
font-style: $style;
|
||||
font-display: swap;
|
||||
}
|
||||
}
|
||||
68
frontend/app/assets/css/_graph.scss
Normal file
68
frontend/app/assets/css/_graph.scss
Normal file
@@ -0,0 +1,68 @@
|
||||
// ---------- Graph view (the link map) ----------
|
||||
|
||||
// desktop: the map owns the space beside the sidebar the way the open
|
||||
// book does — a full surface with its toolbar floating over it.
|
||||
// (The page transition only fades, so no transform steals the
|
||||
// fixed positioning.)
|
||||
.graph-stage {
|
||||
position: fixed;
|
||||
inset: 0 0 0 var(--sidebar-w);
|
||||
transition: left 0.22s ease;
|
||||
z-index: 1;
|
||||
background: var(--bg);
|
||||
}
|
||||
|
||||
.graph-canvas-wrap { position: absolute; inset: 0; }
|
||||
|
||||
.graph-canvas {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
touch-action: none; // the map owns drags and pinches, not the page
|
||||
}
|
||||
|
||||
.graph-toolbar {
|
||||
position: absolute;
|
||||
top: 16px;
|
||||
right: 18px;
|
||||
z-index: 2;
|
||||
display: flex;
|
||||
gap: 2px;
|
||||
padding: 4px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 11px;
|
||||
background: color-mix(in srgb, var(--bg-elev) 84%, transparent);
|
||||
backdrop-filter: blur(10px);
|
||||
box-shadow: var(--shadow-sm);
|
||||
}
|
||||
|
||||
.graph-state {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
padding: 24px;
|
||||
|
||||
.banner { width: min(520px, 100%); }
|
||||
}
|
||||
|
||||
// the top bar is in the flow here, so the map folds into a panel of
|
||||
// the page instead of covering the screen
|
||||
@media (max-width: 900px) {
|
||||
.graph-stage { position: static; inset: auto; background: transparent; }
|
||||
|
||||
.graph-canvas-wrap {
|
||||
position: relative;
|
||||
height: min(66dvh, 560px);
|
||||
margin: 20px 0 28px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 14px;
|
||||
overflow: hidden;
|
||||
background: var(--bg-elev);
|
||||
box-shadow: var(--shadow-sm);
|
||||
}
|
||||
|
||||
.graph-toolbar { top: 10px; right: 10px; }
|
||||
|
||||
.graph-state { position: static; display: block; padding: 8px 0 32px; }
|
||||
}
|
||||
152
frontend/app/assets/css/_home.scss
Normal file
152
frontend/app/assets/css/_home.scss
Normal file
@@ -0,0 +1,152 @@
|
||||
// ---------- Hero (home) ----------
|
||||
.home-main {
|
||||
position: relative;
|
||||
|
||||
&::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
inset: -120px -20% auto -20%;
|
||||
height: 480px;
|
||||
pointer-events: none;
|
||||
background:
|
||||
radial-gradient(38% 60% at 30% 30%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 70%),
|
||||
radial-gradient(34% 55% at 72% 22%, color-mix(in srgb, var(--accent-2) 14%, transparent), transparent 70%);
|
||||
filter: blur(30px);
|
||||
}
|
||||
}
|
||||
|
||||
.hero {
|
||||
position: relative;
|
||||
text-align: center;
|
||||
padding: clamp(56px, 11vh, 104px) 0 44px;
|
||||
|
||||
h1 {
|
||||
margin: 0;
|
||||
font-size: clamp(2.4rem, 6vw, 3.7rem);
|
||||
font-weight: 850;
|
||||
letter-spacing: -0.035em;
|
||||
line-height: 1.08;
|
||||
|
||||
// the headline's ink drifts between the two accents — the gradient is
|
||||
// painted twice as wide as the text and slides through it; both ends are
|
||||
// the accent colour, so the loop has no seam
|
||||
.gradient {
|
||||
background: linear-gradient(
|
||||
92deg,
|
||||
var(--accent) 10%,
|
||||
var(--accent-2) 50%,
|
||||
var(--accent) 90%
|
||||
);
|
||||
background-size: 200% 100%;
|
||||
-webkit-background-clip: text;
|
||||
background-clip: text;
|
||||
color: transparent;
|
||||
animation: hero-gradient-pan 4.5s linear infinite;
|
||||
}
|
||||
}
|
||||
|
||||
.sub {
|
||||
margin: 18px auto 0;
|
||||
max-width: 56ch;
|
||||
color: var(--muted);
|
||||
font-size: clamp(1rem, 1.6vw, 1.13rem);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes hero-gradient-pan {
|
||||
to { background-position-x: 200%; }
|
||||
}
|
||||
|
||||
.search-wrap {
|
||||
position: relative;
|
||||
max-width: 620px;
|
||||
margin: 34px auto 0;
|
||||
|
||||
svg {
|
||||
position: absolute;
|
||||
left: 19px;
|
||||
top: 50%;
|
||||
translate: 0 -50%;
|
||||
color: var(--faint);
|
||||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
|
||||
.search-input {
|
||||
width: 100%;
|
||||
height: 58px;
|
||||
padding: 0 52px 0 52px;
|
||||
border-radius: 16px;
|
||||
border: 1px solid var(--border);
|
||||
background: var(--surface);
|
||||
box-shadow: var(--shadow-sm);
|
||||
font-size: 1rem;
|
||||
transition: border-color 0.15s, box-shadow 0.2s;
|
||||
|
||||
&::placeholder { color: var(--faint); }
|
||||
|
||||
&:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
|
||||
}
|
||||
|
||||
.search-kbd {
|
||||
position: absolute;
|
||||
right: 16px;
|
||||
top: 50%;
|
||||
translate: 0 -50%;
|
||||
font-size: 0.72rem;
|
||||
font-weight: 600;
|
||||
color: var(--faint);
|
||||
border: 1px solid var(--border);
|
||||
border-bottom-width: 2px;
|
||||
border-radius: 6px;
|
||||
padding: 2px 7px;
|
||||
background: var(--surface-2);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.hero-actions {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 12px;
|
||||
margin-top: 22px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
// ---------- Section / results meta ----------
|
||||
.results-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
flex-wrap: wrap;
|
||||
margin: 10px 0 18px;
|
||||
|
||||
h2 {
|
||||
margin: 0;
|
||||
font-size: 1.05rem;
|
||||
font-weight: 700;
|
||||
letter-spacing: -0.01em;
|
||||
color: var(--text);
|
||||
}
|
||||
}
|
||||
|
||||
.filter-chip {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 7px;
|
||||
padding: 5px 12px;
|
||||
border-radius: 999px;
|
||||
background: color-mix(in srgb, var(--accent) 12%, transparent);
|
||||
color: var(--accent);
|
||||
font-size: 0.82rem;
|
||||
font-weight: 600;
|
||||
|
||||
button {
|
||||
color: inherit;
|
||||
opacity: 0.75;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
|
||||
&:hover { opacity: 1; }
|
||||
}
|
||||
}
|
||||
193
frontend/app/assets/css/_langs.scss
Normal file
193
frontend/app/assets/css/_langs.scss
Normal file
@@ -0,0 +1,193 @@
|
||||
@use 'mixins' as *;
|
||||
|
||||
// ---------- Languages ----------
|
||||
|
||||
// the round accent badge a language code wears, on its own or beside a globe
|
||||
@mixin lang-pill {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 2px 9px;
|
||||
border-radius: 999px;
|
||||
border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
|
||||
background: color-mix(in srgb, var(--accent) 8%, transparent);
|
||||
color: var(--accent);
|
||||
font-weight: 700;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.lang-badge { @include lang-pill; font-size: 0.72rem; letter-spacing: 0.02em; }
|
||||
|
||||
// the language link in an article's eyebrow — click to see that language only
|
||||
.article-lang {
|
||||
color: var(--accent);
|
||||
font-weight: 600;
|
||||
text-decoration: none;
|
||||
border-bottom: 1px dashed color-mix(in srgb, var(--accent) 45%, transparent);
|
||||
|
||||
&:hover { border-bottom-style: solid; }
|
||||
}
|
||||
|
||||
// the quiet label that introduces a row of language/version chips
|
||||
.lang-row-label,
|
||||
.article-langs-label,
|
||||
.version-bar-label {
|
||||
font-size: 0.75rem;
|
||||
font-weight: 700;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.06em;
|
||||
color: var(--faint);
|
||||
margin-right: 2px;
|
||||
}
|
||||
|
||||
// language filter chips on the articles index
|
||||
.lang-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
margin: 2px 0 18px;
|
||||
}
|
||||
|
||||
.lang-chip {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 7px;
|
||||
padding: 5px 12px;
|
||||
border-radius: 999px;
|
||||
border: 1px solid var(--border);
|
||||
background: var(--surface);
|
||||
color: var(--text);
|
||||
font-size: 0.82rem;
|
||||
font-weight: 600;
|
||||
transition: border-color 0.15s, background-color 0.15s;
|
||||
|
||||
&:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
|
||||
|
||||
&.active {
|
||||
background: color-mix(in srgb, var(--accent) 12%, transparent);
|
||||
border-color: color-mix(in srgb, var(--accent) 40%, transparent);
|
||||
color: var(--accent);
|
||||
}
|
||||
}
|
||||
|
||||
// the version switcher of an article in the reader (links, not buttons)
|
||||
a.lang-chip { text-decoration: none; }
|
||||
|
||||
.article-langs {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
// the editor's notice while translating an article
|
||||
.translate-banner {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 12px 16px;
|
||||
margin-bottom: 18px;
|
||||
border-radius: 12px;
|
||||
border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--border));
|
||||
background: color-mix(in srgb, var(--accent) 7%, transparent);
|
||||
color: var(--muted);
|
||||
font-size: 0.9rem;
|
||||
|
||||
svg { color: var(--accent); flex: none; }
|
||||
|
||||
a {
|
||||
color: var(--accent);
|
||||
font-weight: 650;
|
||||
text-decoration: none;
|
||||
|
||||
&:hover { text-decoration: underline; }
|
||||
}
|
||||
}
|
||||
|
||||
// the editor's own version bar: the article's languages as chips, with the
|
||||
// unsaved ones wearing a dot, and a dropdown to add another language
|
||||
.version-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.dirty-dot {
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
border-radius: 50%;
|
||||
background: var(--accent);
|
||||
flex: none;
|
||||
}
|
||||
|
||||
.version-add { position: relative; }
|
||||
|
||||
.version-dropdown {
|
||||
@include dropdown-panel;
|
||||
left: 0;
|
||||
min-width: 190px;
|
||||
max-height: 280px;
|
||||
}
|
||||
|
||||
// the card of an article that exists in several languages: the codes ride
|
||||
// together beside a globe, so one card says the whole story
|
||||
.card-langs {
|
||||
@include lang-pill;
|
||||
gap: 5px;
|
||||
font-size: 0.66rem;
|
||||
letter-spacing: 0.04em;
|
||||
|
||||
svg { opacity: 0.85; }
|
||||
}
|
||||
|
||||
// the reader's language menu: a button on the article's actions, opening a
|
||||
// list of every language — the ones to read in, and the ones left to write
|
||||
.lang-menu { position: relative; }
|
||||
|
||||
.lang-menu-caret { opacity: 0.6; }
|
||||
|
||||
.lang-menu-dropdown {
|
||||
@include dropdown-panel($z: 30);
|
||||
right: 0;
|
||||
min-width: 220px;
|
||||
max-height: 340px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.lang-menu-section { @include eyebrow(0.68rem, 700, 0.06em); padding: 7px 10px 4px; }
|
||||
|
||||
.lang-menu-gap { margin-top: 5px; border-top: 1px solid var(--border); padding-top: 9px; }
|
||||
|
||||
.lang-menu-item {
|
||||
@include menu-row(7px 10px, 9px);
|
||||
text-decoration: none;
|
||||
|
||||
&:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }
|
||||
|
||||
.lmi-sub {
|
||||
margin-left: auto;
|
||||
max-width: 112px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
font-size: 0.72rem;
|
||||
font-weight: 500;
|
||||
color: var(--faint);
|
||||
}
|
||||
|
||||
.lmi-check { flex: none; color: var(--accent); }
|
||||
}
|
||||
|
||||
.lang-menu-write {
|
||||
.lmi-pencil {
|
||||
margin-left: auto;
|
||||
flex: none;
|
||||
color: var(--faint);
|
||||
transition: color 0.12s;
|
||||
}
|
||||
|
||||
&:hover .lmi-pencil { color: var(--accent); }
|
||||
}
|
||||
283
frontend/app/assets/css/_layout.scss
Normal file
283
frontend/app/assets/css/_layout.scss
Normal file
@@ -0,0 +1,283 @@
|
||||
@use 'mixins' as *;
|
||||
|
||||
// ---------- Layout shell ----------
|
||||
.app-shell { display: flex; min-height: 100vh; }
|
||||
|
||||
.app-main { flex: 1; min-width: 0; }
|
||||
|
||||
// ---------- Sidebar (site navigation) ----------
|
||||
.site-sidebar {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 60;
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
width: var(--sidebar-w);
|
||||
height: 100vh;
|
||||
padding: 22px 18px;
|
||||
backdrop-filter: blur(14px);
|
||||
background: color-mix(in srgb, var(--bg) 78%, transparent);
|
||||
border-right: 1px solid var(--border);
|
||||
transition: width 0.22s ease, padding 0.22s ease;
|
||||
}
|
||||
|
||||
.sidebar-nav {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
gap: 6px;
|
||||
margin-top: 26px;
|
||||
|
||||
.btn { justify-content: center; margin-top: 6px; }
|
||||
}
|
||||
|
||||
.sidebar-footer {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 10px;
|
||||
margin-top: auto;
|
||||
|
||||
// the footer buttons read as nav rows — icon then label, centred, taking the
|
||||
// sidebar's width so they grow and shrink with it (both classes are grid, which
|
||||
// would drop the label under the icon, and the label shows on mobile too, so
|
||||
// the row layout lives outside the desktop block)
|
||||
.panel-icon-btn,
|
||||
.icon-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
font-size: 0.86rem;
|
||||
font-weight: 550;
|
||||
white-space: nowrap;
|
||||
|
||||
svg { flex-shrink: 0; }
|
||||
}
|
||||
}
|
||||
|
||||
// The account row: who the wiki is being written as. It reads as one of the
|
||||
// sidebar's rows — an initial in a circle, the name while the sidebar has room
|
||||
// for it, and the way out at the end of the line.
|
||||
.account-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
padding: 6px 10px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 10px;
|
||||
color: var(--muted);
|
||||
font-size: 0.86rem;
|
||||
font-weight: 550;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.account-avatar { @include avatar(30px, 0.84rem); }
|
||||
|
||||
// the row's avatar and name together form the button that opens the profile
|
||||
// popup; the exit button beside it stays its own
|
||||
.account-open {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
border-radius: 9px;
|
||||
text-align: left;
|
||||
|
||||
&:hover .account-avatar { background: color-mix(in srgb, var(--accent) 24%, transparent); }
|
||||
|
||||
&:hover .account-name { color: var(--accent); }
|
||||
}
|
||||
|
||||
.account-name {
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
.account-exit {
|
||||
@include icon-target(24px, 7px);
|
||||
color: var(--faint);
|
||||
transition: color 0.15s, background-color 0.15s;
|
||||
|
||||
&:hover { background: var(--surface-2); color: var(--danger); }
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.app-shell { flex-direction: column; }
|
||||
|
||||
.site-sidebar {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
row-gap: 10px;
|
||||
padding: 12px clamp(16px, 4vw, 32px);
|
||||
border-right: 0;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.sidebar-nav {
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
margin-top: 0;
|
||||
|
||||
.btn { margin-top: 0; }
|
||||
}
|
||||
|
||||
.sidebar-search { width: auto; min-width: 132px; max-width: 240px; }
|
||||
|
||||
.sidebar-footer { margin-top: 0; flex-direction: row; align-items: center; }
|
||||
|
||||
// the rail is a desktop affordance — the top bar is always expanded
|
||||
.sidebar-collapse-btn { display: none; }
|
||||
}
|
||||
|
||||
// ---------- Collapsed sidebar: an icon rail (desktop only) ----------
|
||||
.sidebar-collapse-btn svg { transition: transform 0.22s ease; }
|
||||
|
||||
@media (min-width: 901px) {
|
||||
// desktop: stack above the reading surface (book layer, z 70/74) so the
|
||||
// book's edge shadow falls behind the nav instead of darkening it
|
||||
.site-sidebar { z-index: 75; }
|
||||
|
||||
// on desktop they fill the sidebar's width instead of their own: the collapsing
|
||||
// sidebar relayouts them every frame, the rail drops their labels (.hide-collapsed)
|
||||
// and their fixed heights hold, so the icons ride the centre the whole way
|
||||
.sidebar-footer .panel-icon-btn,
|
||||
.sidebar-footer .icon-btn,
|
||||
.sidebar-footer .account-row {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
// the root class also moves the fixed reading surface in step, since
|
||||
// --sidebar-w feeds the book layer's left inset
|
||||
html.sidebar-collapsed { --sidebar-w: 68px; }
|
||||
|
||||
.site-sidebar.collapsed {
|
||||
padding-inline: 12px;
|
||||
|
||||
.sidebar-collapse-btn svg { transform: rotate(180deg); }
|
||||
|
||||
// with the labels gone, center what's left: the icons. The buttons keep
|
||||
// the height the labels used to give them (font-size x line-height 1.6
|
||||
// + their vertical padding), so the rail doesn't shrink them
|
||||
.sidebar-search {
|
||||
justify-content: center;
|
||||
padding-inline: 0;
|
||||
min-height: 40px; // 9+9 padding + 13.76px x 1.6 label line
|
||||
}
|
||||
|
||||
.nav-link {
|
||||
justify-content: center;
|
||||
padding-inline: 0;
|
||||
min-height: 39px; // 8+8 padding + 14.4px x 1.6 label line
|
||||
}
|
||||
|
||||
.sidebar-nav .btn {
|
||||
min-height: 35px; // 7+7 padding + 13.12px x 1.6 label line
|
||||
}
|
||||
|
||||
// the mark is all that's left of the wordmark, so it rides the rail's
|
||||
// centre like the icons beside it
|
||||
.logo { justify-content: center; }
|
||||
|
||||
// the way out drops away with the labels, leaving just the avatar centred
|
||||
// on the rail; the avatar sets the row's height now, so the rail doesn't
|
||||
// shrink it
|
||||
.account-row {
|
||||
min-height: 44px; // 1+1 border + 6+6 padding + 30px avatar
|
||||
}
|
||||
}
|
||||
|
||||
// collapsing drops the labels at once; expanding waits for the rail to
|
||||
// open before fading them back in, so they never render squished at
|
||||
// half width mid-transition
|
||||
.hide-collapsed { transition: opacity 0.16s ease 0.1s, display 0.26s allow-discrete; }
|
||||
|
||||
@starting-style {
|
||||
.hide-collapsed { opacity: 0; }
|
||||
}
|
||||
|
||||
html.sidebar-collapsed .hide-collapsed { display: none; transition: none; }
|
||||
}
|
||||
|
||||
// ---------- "Open" articles: the count beside the button that shows them ----------
|
||||
.sidebar-open.is-current {
|
||||
color: var(--accent);
|
||||
background: color-mix(in srgb, var(--accent) 9%, transparent);
|
||||
}
|
||||
|
||||
.tabs-count {
|
||||
margin-left: auto;
|
||||
min-width: 18px;
|
||||
height: 18px;
|
||||
padding: 0 5px;
|
||||
display: inline-grid;
|
||||
place-items: center;
|
||||
border-radius: 9px;
|
||||
background: color-mix(in srgb, var(--accent) 14%, transparent);
|
||||
color: var(--accent);
|
||||
font-size: 0.68rem;
|
||||
font-weight: 700;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.logo {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 11px;
|
||||
text-decoration: none;
|
||||
color: var(--text);
|
||||
font-weight: 800;
|
||||
font-size: 1.15rem;
|
||||
letter-spacing: -0.02em;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
// a 40px square — the height the nav rows settle at (the search bar's own
|
||||
// padding + label line), so the sigma reads as one of the sidebar's buttons
|
||||
.logo-mark {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 11px;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
background: linear-gradient(135deg, var(--accent), var(--accent-2));
|
||||
color: #fff;
|
||||
font-size: 1.4rem;
|
||||
font-weight: 700;
|
||||
box-shadow: 0 4px 14px -4px color-mix(in srgb, var(--accent) 60%, transparent);
|
||||
}
|
||||
|
||||
.logo-accent { @include gradient-text; }
|
||||
|
||||
.nav-link {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 7px;
|
||||
padding: 8px 13px;
|
||||
border-radius: 9px;
|
||||
color: var(--muted);
|
||||
text-decoration: none;
|
||||
font-size: 0.9rem;
|
||||
font-weight: 550;
|
||||
@include hover-row;
|
||||
|
||||
&.router-link-active {
|
||||
color: var(--accent);
|
||||
background: color-mix(in srgb, var(--accent) 9%, transparent);
|
||||
}
|
||||
}
|
||||
|
||||
// small icon button used in modal/popup headers
|
||||
.panel-icon-btn { @include icon-target(30px, 8px); color: var(--muted); @include hover-row; }
|
||||
211
frontend/app/assets/css/_mixins.scss
Normal file
211
frontend/app/assets/css/_mixins.scss
Normal file
@@ -0,0 +1,211 @@
|
||||
// Shared shapes the rest of the design is cut from. Colours stay CSS custom
|
||||
// properties throughout — [data-theme]/[data-accent] swap them at runtime.
|
||||
|
||||
// the dark backdrop a popup opens onto ($pad-y: how far down the sheet sits)
|
||||
@mixin overlay($z, $pad-y: clamp(56px, 13vh, 132px)) {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: $z;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: flex-start;
|
||||
padding: $pad-y 16px 16px;
|
||||
background: color-mix(in srgb, #05070d 55%, transparent);
|
||||
backdrop-filter: blur(3px);
|
||||
}
|
||||
|
||||
// the paper dropped under a backdrop
|
||||
@mixin sheet($w, $max-h: null) {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: min($w, 100%);
|
||||
@if $max-h {
|
||||
max-height: $max-h;
|
||||
}
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 16px;
|
||||
background: var(--bg-elev);
|
||||
box-shadow: var(--shadow-lg);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
// a popup's title row: the title, and the × at the end of it
|
||||
@mixin sheet-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
padding: 13px 14px 13px 18px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
@mixin sheet-title {
|
||||
margin: 0;
|
||||
font-size: 1.02rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
// the scrolling middle of a popup
|
||||
@mixin sheet-body($pad: 18px) {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
padding: $pad;
|
||||
scrollbar-width: thin;
|
||||
}
|
||||
|
||||
// the opening animation every popup shares: the backdrop fades, the sheet
|
||||
// slides in from the edge it hangs nearest ($offset is where it starts)
|
||||
@mixin popup-anim($name, $sheet, $dur, $sheet-move, $offset) {
|
||||
.#{$name}-enter-active,
|
||||
.#{$name}-leave-active {
|
||||
transition: opacity $dur ease;
|
||||
|
||||
#{$sheet} { transition: $sheet-move; }
|
||||
}
|
||||
|
||||
.#{$name}-enter-from,
|
||||
.#{$name}-leave-to {
|
||||
opacity: 0;
|
||||
|
||||
#{$sheet} { transform: translateY($offset) scale(0.98); }
|
||||
}
|
||||
}
|
||||
|
||||
// a menu that drops from a button: the popups' paper, on a hinge
|
||||
// ($overflow: `auto` once it caps at a max-height; `visible` may not clip
|
||||
// a nested dropdown)
|
||||
@mixin dropdown-panel($z: 20, $overflow: auto) {
|
||||
position: absolute;
|
||||
z-index: $z;
|
||||
top: calc(100% + 6px);
|
||||
padding: 6px;
|
||||
overflow-y: $overflow;
|
||||
border-radius: 12px;
|
||||
border: 1px solid var(--border);
|
||||
background: var(--bg-elev);
|
||||
box-shadow: var(--shadow-lg);
|
||||
}
|
||||
|
||||
// a row inside a dropdown: full width, icon then label, an accent wash on hover
|
||||
@mixin menu-row($pad, $gap, $fs: 0.85rem) {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: $gap;
|
||||
width: 100%;
|
||||
padding: $pad;
|
||||
border-radius: 8px;
|
||||
color: var(--text);
|
||||
font-size: $fs;
|
||||
font-weight: 600;
|
||||
transition: background-color 0.12s;
|
||||
}
|
||||
|
||||
// the small caps label over a section of the interface
|
||||
@mixin eyebrow($fs: 0.72rem, $fw: 750, $ls: 0.1em, $color: var(--faint)) {
|
||||
font-size: $fs;
|
||||
font-weight: $fw;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: $ls;
|
||||
color: $color;
|
||||
}
|
||||
|
||||
// the account's face in a circle: an initial, or a picture laid over it
|
||||
@mixin avatar($size, $fs) {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
flex-shrink: 0;
|
||||
width: $size;
|
||||
height: $size;
|
||||
border-radius: 50%;
|
||||
background: color-mix(in srgb, var(--accent) 14%, transparent);
|
||||
color: var(--accent);
|
||||
font-size: $fs;
|
||||
font-weight: 800;
|
||||
line-height: 1;
|
||||
overflow: hidden;
|
||||
|
||||
img {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border-radius: 50%;
|
||||
object-fit: cover;
|
||||
}
|
||||
}
|
||||
|
||||
// a square target that centres its icon
|
||||
@mixin icon-target($size, $radius) {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
flex-shrink: 0;
|
||||
width: $size;
|
||||
height: $size;
|
||||
border-radius: $radius;
|
||||
}
|
||||
|
||||
// a quiet row that warms on hover (nav links, icon buttons)
|
||||
@mixin hover-row {
|
||||
transition: color 0.15s, background-color 0.15s;
|
||||
|
||||
&:hover { color: var(--text); background: var(--surface-2); }
|
||||
}
|
||||
|
||||
// a row of choices styled as one segmented control
|
||||
@mixin segmented {
|
||||
display: inline-flex;
|
||||
gap: 4px;
|
||||
padding: 4px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 12px;
|
||||
background: var(--surface-2);
|
||||
}
|
||||
|
||||
@mixin segmented-tab($pad, $fs) {
|
||||
padding: $pad;
|
||||
border-radius: 9px;
|
||||
background: transparent;
|
||||
color: var(--muted);
|
||||
font-size: $fs;
|
||||
font-weight: 600;
|
||||
transition: color 0.15s, background-color 0.15s, box-shadow 0.15s;
|
||||
|
||||
&:hover { color: var(--text); }
|
||||
|
||||
&.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
|
||||
}
|
||||
|
||||
// the loading shimmer a skeleton wears
|
||||
@mixin shimmer {
|
||||
background: linear-gradient(
|
||||
100deg,
|
||||
var(--surface) 40%,
|
||||
color-mix(in srgb, var(--surface) 55%, var(--text) 9%) 50%,
|
||||
var(--surface) 60%
|
||||
);
|
||||
background-size: 200% 100%;
|
||||
animation: shimmer 1.4s infinite linear;
|
||||
}
|
||||
|
||||
// paint text with a gradient between the two accents
|
||||
@mixin gradient-text($angle: 90deg) {
|
||||
background: linear-gradient($angle, var(--accent), var(--accent-2));
|
||||
-webkit-background-clip: text;
|
||||
background-clip: text;
|
||||
color: transparent;
|
||||
}
|
||||
|
||||
// a row of the book: no gutter along its edge (a book has none)
|
||||
@mixin no-scrollbar {
|
||||
scrollbar-width: none;
|
||||
|
||||
&::-webkit-scrollbar { display: none; }
|
||||
}
|
||||
|
||||
// the × that closes a page or a chip: faint, and turns danger on hover
|
||||
@mixin close-target {
|
||||
&:hover {
|
||||
color: var(--danger);
|
||||
background: color-mix(in srgb, var(--danger) 10%, transparent);
|
||||
}
|
||||
}
|
||||
91
frontend/app/assets/css/_profile.scss
Normal file
91
frontend/app/assets/css/_profile.scss
Normal file
@@ -0,0 +1,91 @@
|
||||
@use 'mixins' as *;
|
||||
|
||||
// ---------- Profile popup ----------
|
||||
// The account row in the sidebar opens it; it draws and closes in the same
|
||||
// shape as the settings popup. Holds the profile picture (a data URL kept on
|
||||
// the account), the username, the password, and the way out.
|
||||
.profile-overlay { @include overlay(120); }
|
||||
|
||||
.profile-modal {
|
||||
@include sheet(460px, min(620px, calc(100vh - 110px)));
|
||||
|
||||
&:focus, &:focus-visible { outline: none; }
|
||||
}
|
||||
|
||||
.profile-modal-head { @include sheet-head; }
|
||||
|
||||
.profile-title { @include sheet-title; }
|
||||
|
||||
.profile-modal-body { @include sheet-body; }
|
||||
|
||||
.profile-group + .profile-group {
|
||||
margin-top: 22px;
|
||||
padding-top: 22px;
|
||||
border-top: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.profile-group-head {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.profile-group-title { font-size: 0.92rem; font-weight: 700; color: var(--text); }
|
||||
|
||||
.profile-group-hint { font-size: 0.8rem; color: var(--muted); }
|
||||
|
||||
// the big avatar beside its buttons
|
||||
.profile-avatar-row { display: flex; align-items: center; gap: 18px; }
|
||||
|
||||
.profile-avatar { @include avatar(72px, 1.7rem); }
|
||||
|
||||
.profile-avatar-actions {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
// the file chooser is driven by the buttons above it, never shown itself
|
||||
.profile-file-input { display: none; }
|
||||
|
||||
.profile-form {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
|
||||
input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
padding: 10px 13px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 10px;
|
||||
background: var(--bg-elev);
|
||||
font-size: 0.88rem;
|
||||
transition: border-color 0.15s, box-shadow 0.2s;
|
||||
|
||||
&:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
|
||||
}
|
||||
|
||||
// the password pair stack one per line, the button below them
|
||||
&-password input { flex: 1 1 100%; }
|
||||
}
|
||||
|
||||
.profile-saved {
|
||||
margin: 8px 0 0;
|
||||
font-size: 0.8rem;
|
||||
font-weight: 600;
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
.profile-signout { margin-top: 2px; }
|
||||
|
||||
@include popup-anim(
|
||||
'profile-popup',
|
||||
'.profile-modal',
|
||||
0.16s,
|
||||
transform 0.2s cubic-bezier(0.22, 0.61, 0.36, 1),
|
||||
-10px
|
||||
);
|
||||
167
frontend/app/assets/css/_prose.scss
Normal file
167
frontend/app/assets/css/_prose.scss
Normal file
@@ -0,0 +1,167 @@
|
||||
@use 'mixins' as *;
|
||||
|
||||
// ---------- Prose (rendered markdown) ----------
|
||||
.prose {
|
||||
font-size: 1.02rem;
|
||||
line-height: 1.75;
|
||||
color: var(--text);
|
||||
overflow-wrap: break-word;
|
||||
|
||||
> :first-child { margin-top: 0; }
|
||||
|
||||
> :first-child > :first-child, h1:first-child { margin-top: 0.6em; }
|
||||
|
||||
h1,
|
||||
h2,
|
||||
h3,
|
||||
h4 {
|
||||
scroll-margin-top: 90px;
|
||||
line-height: 1.25;
|
||||
letter-spacing: -0.02em;
|
||||
font-weight: 730;
|
||||
}
|
||||
|
||||
h1 { font-size: 1.85rem; margin: 1.4em 0 0.5em; }
|
||||
|
||||
h2 {
|
||||
font-size: 1.42rem;
|
||||
margin: 2.1em 0 0.55em;
|
||||
padding-bottom: 0.32em;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
h3 { font-size: 1.17rem; margin: 1.7em 0 0.45em; }
|
||||
|
||||
h4 { font-size: 1.02rem; margin: 1.5em 0 0.4em; }
|
||||
|
||||
p { margin: 0.95em 0; }
|
||||
|
||||
a {
|
||||
color: var(--accent);
|
||||
text-decoration: none;
|
||||
border-bottom: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
|
||||
transition: border-color 0.15s, color 0.15s;
|
||||
|
||||
&:hover { color: var(--accent-strong); border-bottom-color: currentColor; }
|
||||
|
||||
// internal wiki links written as [[Article Title]]
|
||||
&.wikilink { border-bottom-style: dotted; }
|
||||
}
|
||||
|
||||
strong { font-weight: 730; }
|
||||
|
||||
ul, ol { padding-left: 1.45em; margin: 0.9em 0; }
|
||||
|
||||
li {
|
||||
margin: 0.35em 0;
|
||||
|
||||
&::marker { color: var(--faint); }
|
||||
}
|
||||
|
||||
blockquote {
|
||||
margin: 1.4em 0;
|
||||
padding: 0.75em 1.2em;
|
||||
border-left: 3px solid var(--accent);
|
||||
background: color-mix(in srgb, var(--accent) 6%, transparent);
|
||||
border-radius: 0 12px 12px 0;
|
||||
color: var(--muted);
|
||||
|
||||
p { margin: 0.2em 0; }
|
||||
}
|
||||
|
||||
hr { border: 0; border-top: 1px solid var(--border); margin: 2.4em 0; }
|
||||
|
||||
table {
|
||||
display: block;
|
||||
width: max-content;
|
||||
max-width: 100%;
|
||||
overflow-x: auto;
|
||||
border-collapse: collapse;
|
||||
margin: 1.5em 0;
|
||||
font-size: 0.94em;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
thead { background: var(--surface-2); }
|
||||
|
||||
th, td { padding: 0.58em 0.95em; border: 1px solid var(--border); text-align: left; }
|
||||
|
||||
tbody tr:nth-child(even) { background: color-mix(in srgb, var(--surface) 55%, transparent); }
|
||||
|
||||
img { max-width: 100%; border-radius: 12px; }
|
||||
|
||||
kbd {
|
||||
font-family: inherit;
|
||||
font-size: 0.8em;
|
||||
border: 1px solid var(--border);
|
||||
border-bottom-width: 2px;
|
||||
border-radius: 6px;
|
||||
padding: 1px 6px;
|
||||
background: var(--surface-2);
|
||||
}
|
||||
|
||||
// inline code
|
||||
code {
|
||||
background: color-mix(in srgb, var(--text) 8%, transparent);
|
||||
border: 1px solid var(--border);
|
||||
padding: 0.12em 0.42em;
|
||||
border-radius: 6px;
|
||||
font-size: 0.86em;
|
||||
}
|
||||
|
||||
pre {
|
||||
margin: 1.4em 0;
|
||||
padding: 17px 20px;
|
||||
border-radius: 13px;
|
||||
border: 1px solid var(--border);
|
||||
background: var(--code-bg);
|
||||
overflow-x: auto;
|
||||
line-height: 1.65;
|
||||
font-size: 0.875rem;
|
||||
|
||||
code {
|
||||
background: none;
|
||||
border: 0;
|
||||
padding: 0;
|
||||
font-size: inherit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// code tokens (highlight.js)
|
||||
.hljs-keyword, .hljs-selector-tag, .hljs-doctag { color: var(--tok-key); }
|
||||
|
||||
.hljs-string, .hljs-regexp, .hljs-addition { color: var(--tok-str); }
|
||||
|
||||
.hljs-comment { color: var(--tok-com); font-style: italic; }
|
||||
|
||||
.hljs-number, .hljs-variable, .hljs-template-variable { color: var(--tok-num); }
|
||||
|
||||
.hljs-title, .hljs-title.function_, .hljs-section { color: var(--tok-fn); }
|
||||
|
||||
.hljs-built_in,
|
||||
.hljs-type,
|
||||
.hljs-class .hljs-title,
|
||||
.hljs-title.class_ {
|
||||
color: var(--tok-built);
|
||||
}
|
||||
|
||||
.hljs-literal, .hljs-symbol, .hljs-bullet, .hljs-link { color: var(--tok-lit); }
|
||||
|
||||
.hljs-attr, .hljs-attribute, .hljs-property, .hljs-meta { color: var(--tok-meta); }
|
||||
|
||||
.hljs-deletion { color: var(--danger); }
|
||||
|
||||
// ---------- KaTeX ----------
|
||||
.katex { font-size: 1.06em; }
|
||||
|
||||
.prose .katex-display {
|
||||
margin: 1.35em 0;
|
||||
padding: 0.3em 0.2em;
|
||||
overflow-x: auto;
|
||||
overflow-y: hidden;
|
||||
scrollbar-width: thin;
|
||||
}
|
||||
|
||||
.prose .katex-error { color: var(--danger); font-family: inherit; }
|
||||
182
frontend/app/assets/css/_search.scss
Normal file
182
frontend/app/assets/css/_search.scss
Normal file
@@ -0,0 +1,182 @@
|
||||
@use 'mixins' as *;
|
||||
|
||||
// ---------- Search (sidebar bar + centered popup) ----------
|
||||
.sidebar-search {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
width: 100%;
|
||||
padding: 9px 12px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 10px;
|
||||
background: var(--surface);
|
||||
color: var(--faint);
|
||||
font-size: 0.86rem;
|
||||
font-weight: 550;
|
||||
text-align: left;
|
||||
box-shadow: var(--shadow-sm);
|
||||
transition: border-color 0.15s, color 0.15s;
|
||||
|
||||
&:hover { border-color: var(--border-strong); color: var(--muted); }
|
||||
|
||||
svg { flex-shrink: 0; }
|
||||
}
|
||||
|
||||
.sidebar-search-label {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.kbd-hint {
|
||||
font-family: inherit;
|
||||
font-size: 0.68rem;
|
||||
font-weight: 600;
|
||||
color: var(--faint);
|
||||
border: 1px solid var(--border);
|
||||
border-bottom-width: 2px;
|
||||
border-radius: 5px;
|
||||
padding: 0 5px;
|
||||
background: var(--surface-2);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.search-overlay { @include overlay(120); }
|
||||
|
||||
.search-modal { @include sheet(620px, min(560px, calc(100vh - 110px))); }
|
||||
|
||||
.search-modal-field {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 11px;
|
||||
padding: 13px 16px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
|
||||
svg { flex-shrink: 0; color: var(--faint); }
|
||||
}
|
||||
|
||||
.search-modal-input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
font-size: 1.02rem;
|
||||
|
||||
&:focus, &:focus-visible { outline: none; box-shadow: none; }
|
||||
|
||||
&::placeholder { color: var(--faint); }
|
||||
}
|
||||
|
||||
.search-spinner {
|
||||
flex-shrink: 0;
|
||||
width: 15px;
|
||||
height: 15px;
|
||||
border-radius: 50%;
|
||||
border: 2px solid color-mix(in srgb, var(--accent) 25%, transparent);
|
||||
border-top-color: var(--accent);
|
||||
animation: search-spin 0.7s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes search-spin {
|
||||
to { transform: rotate(1turn); }
|
||||
}
|
||||
|
||||
.search-modal-body {
|
||||
@include sheet-body(8px);
|
||||
|
||||
.banner { margin: 8px 8px 10px; }
|
||||
}
|
||||
|
||||
.search-results { list-style: none; margin: 0; padding: 0; }
|
||||
|
||||
.search-result {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 3px;
|
||||
padding: 10px 12px;
|
||||
border-radius: 11px;
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
transition: background-color 0.12s;
|
||||
|
||||
&.active { background: color-mix(in srgb, var(--accent) 12%, transparent); }
|
||||
}
|
||||
|
||||
.sr-title {
|
||||
font-weight: 650;
|
||||
font-size: 0.94rem;
|
||||
line-height: 1.35;
|
||||
|
||||
mark {
|
||||
background: color-mix(in srgb, var(--accent) 30%, transparent);
|
||||
color: inherit;
|
||||
border-radius: 3px;
|
||||
padding: 0 1px;
|
||||
}
|
||||
}
|
||||
|
||||
.sr-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
margin-top: 1px;
|
||||
font-size: 0.74rem;
|
||||
color: var(--faint);
|
||||
}
|
||||
|
||||
.search-quick-title { @include eyebrow; margin: 6px 8px 4px; }
|
||||
|
||||
.search-none {
|
||||
text-align: center;
|
||||
padding: 32px 16px;
|
||||
color: var(--muted);
|
||||
font-size: 0.88rem;
|
||||
|
||||
strong { color: var(--text); }
|
||||
}
|
||||
|
||||
.search-skeleton {
|
||||
height: 54px;
|
||||
margin: 4px;
|
||||
border-radius: 11px;
|
||||
@include shimmer;
|
||||
}
|
||||
|
||||
.search-modal-foot {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
padding: 9px 14px;
|
||||
border-top: 1px solid var(--border);
|
||||
background: var(--surface);
|
||||
font-size: 0.75rem;
|
||||
color: var(--faint);
|
||||
}
|
||||
|
||||
.foot-hints {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
|
||||
.kbd-hint { margin-right: 4px; }
|
||||
}
|
||||
|
||||
.foot-all {
|
||||
color: var(--accent);
|
||||
text-decoration: none;
|
||||
font-weight: 600;
|
||||
white-space: nowrap;
|
||||
|
||||
&:hover { text-decoration: underline; }
|
||||
}
|
||||
|
||||
@include popup-anim(
|
||||
'search-popup',
|
||||
'.search-modal',
|
||||
0.16s,
|
||||
transform 0.2s cubic-bezier(0.22, 0.61, 0.36, 1),
|
||||
-10px
|
||||
);
|
||||
73
frontend/app/assets/css/_settings.scss
Normal file
73
frontend/app/assets/css/_settings.scss
Normal file
@@ -0,0 +1,73 @@
|
||||
@use 'mixins' as *;
|
||||
|
||||
// ---------- Settings popup ----------
|
||||
.settings-overlay { @include overlay(120); }
|
||||
|
||||
.settings-modal {
|
||||
@include sheet(460px, min(560px, calc(100vh - 110px)));
|
||||
|
||||
&:focus, &:focus-visible { outline: none; }
|
||||
}
|
||||
|
||||
.settings-modal-head { @include sheet-head; }
|
||||
|
||||
.settings-title { @include sheet-title; }
|
||||
|
||||
.settings-modal-body { @include sheet-body; }
|
||||
|
||||
.settings-group + .settings-group {
|
||||
margin-top: 22px;
|
||||
padding-top: 22px;
|
||||
border-top: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.settings-group-head {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.settings-group-title { font-size: 0.92rem; font-weight: 700; color: var(--text); }
|
||||
|
||||
.settings-group-hint { font-size: 0.8rem; color: var(--muted); }
|
||||
|
||||
// segmented light / dark switch
|
||||
.theme-switch { @include segmented; }
|
||||
|
||||
.theme-option {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 7px;
|
||||
@include segmented-tab(8px 16px, 0.86rem);
|
||||
}
|
||||
|
||||
// accent colour swatches
|
||||
.accent-swatches { display: flex; flex-wrap: wrap; gap: 14px; }
|
||||
|
||||
.accent-swatch {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
border-radius: 50%;
|
||||
border: 0;
|
||||
padding: 0;
|
||||
color: #fff;
|
||||
background: linear-gradient(135deg, var(--swatch), var(--swatch-2));
|
||||
transition: transform 0.12s, box-shadow 0.15s;
|
||||
|
||||
&:hover { transform: scale(1.1); }
|
||||
|
||||
&:active { transform: scale(0.94); }
|
||||
|
||||
&.active { box-shadow: 0 0 0 2px var(--bg-elev), 0 0 0 4px var(--swatch); }
|
||||
}
|
||||
|
||||
@include popup-anim(
|
||||
'settings-popup',
|
||||
'.settings-modal',
|
||||
0.16s,
|
||||
transform 0.2s cubic-bezier(0.22, 0.61, 0.36, 1),
|
||||
-10px
|
||||
);
|
||||
46
frontend/app/assets/css/_states.scss
Normal file
46
frontend/app/assets/css/_states.scss
Normal file
@@ -0,0 +1,46 @@
|
||||
@use 'mixins' as *;
|
||||
|
||||
// ---------- States ----------
|
||||
.empty {
|
||||
text-align: center;
|
||||
padding: 72px 20px;
|
||||
color: var(--muted);
|
||||
|
||||
.glyph {
|
||||
font-size: 3.4rem;
|
||||
line-height: 1;
|
||||
margin-bottom: 14px;
|
||||
opacity: 0.65;
|
||||
}
|
||||
|
||||
h3 { margin: 0 0 6px; color: var(--text); font-size: 1.15rem; }
|
||||
|
||||
p { margin: 0 auto 22px; max-width: 42ch; font-size: 0.93rem; }
|
||||
}
|
||||
|
||||
.banner {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 12px;
|
||||
padding: 15px 18px;
|
||||
border-radius: 13px;
|
||||
border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--border));
|
||||
background: color-mix(in srgb, var(--danger) 7%, var(--surface));
|
||||
font-size: 0.9rem;
|
||||
margin: 14px 0;
|
||||
|
||||
.glyph { color: var(--danger); font-weight: 800; }
|
||||
|
||||
code {
|
||||
background: color-mix(in srgb, var(--text) 8%, transparent);
|
||||
padding: 0.1em 0.4em;
|
||||
border-radius: 5px;
|
||||
font-size: 0.85em;
|
||||
}
|
||||
}
|
||||
|
||||
.skeleton { border-radius: 16px; height: 172px; @include shimmer; }
|
||||
|
||||
@keyframes shimmer {
|
||||
to { background-position-x: -200%; }
|
||||
}
|
||||
110
frontend/app/assets/css/_tokens.scss
Normal file
110
frontend/app/assets/css/_tokens.scss
Normal file
@@ -0,0 +1,110 @@
|
||||
@use 'sass:list';
|
||||
|
||||
// ---------- Theme tokens ----------
|
||||
// [data-theme] swaps the surfaces, [data-accent] the accents (no attribute
|
||||
// = violet, the defaults below). Reading-surface sizes live here too: the
|
||||
// sidebar's width feeds the book layer's left inset (see _book.scss).
|
||||
:root {
|
||||
color-scheme: light;
|
||||
--bg: #f7f8fb;
|
||||
--bg-elev: #ffffff;
|
||||
--surface: #ffffff;
|
||||
--surface-2: #eef1f7;
|
||||
--border: #e2e6ef;
|
||||
--border-strong: #cfd5e3;
|
||||
--text: #1b2130;
|
||||
--muted: #5b6478;
|
||||
--faint: #8a93a8;
|
||||
--accent: #4f5fe8;
|
||||
--accent-strong: #3d4dd6;
|
||||
--accent-2: #0ea5c9;
|
||||
--danger: #d1344b;
|
||||
--code-bg: #f4f6fa;
|
||||
--shadow-sm: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 8%);
|
||||
--shadow-lg: 0 4px 12px rgb(16 24 40 / 8%), 0 16px 40px -12px rgb(16 24 40 / 18%);
|
||||
--ring: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
|
||||
|
||||
// code token colors (light)
|
||||
--tok-key: #8250df;
|
||||
--tok-str: #0a3069;
|
||||
--tok-com: #6e7781;
|
||||
--tok-num: #0550ae;
|
||||
--tok-fn: #6639ba;
|
||||
--tok-built: #953800;
|
||||
--tok-lit: #cf222e;
|
||||
--tok-meta: #7d4e00;
|
||||
|
||||
// the reader's book (see _book.scss)
|
||||
--sidebar-w: 232px;
|
||||
--spine-w: 34px;
|
||||
// how wide a page of the book is allowed to get: past this the desk shows
|
||||
// beside the paper rather than the page stretching on and on. The one page
|
||||
// of a book with nothing else in it is exempt (see .book-pane:only-child).
|
||||
--pane-max-w: 60rem;
|
||||
}
|
||||
|
||||
:root[data-theme='dark'] {
|
||||
color-scheme: dark;
|
||||
--bg: #0a0c12;
|
||||
--bg-elev: #10131c;
|
||||
--surface: #141826;
|
||||
--surface-2: #1a2030;
|
||||
--border: #232a3c;
|
||||
--border-strong: #313a52;
|
||||
--text: #e7eaf3;
|
||||
--muted: #99a1b5;
|
||||
--faint: #6b7488;
|
||||
--accent: #7c8cff;
|
||||
--accent-strong: #99a5ff;
|
||||
--accent-2: #38d3ee;
|
||||
--danger: #f47085;
|
||||
--code-bg: #0c0f16;
|
||||
--shadow-sm: 0 1px 2px rgb(0 0 0 / 30%);
|
||||
--shadow-lg: 0 4px 16px rgb(0 0 0 / 40%), 0 24px 48px -16px rgb(0 0 0 / 55%);
|
||||
|
||||
// code token colors (dark)
|
||||
--tok-key: #c792ea;
|
||||
--tok-str: #9ece6a;
|
||||
--tok-com: #565f89;
|
||||
--tok-num: #ff9e64;
|
||||
--tok-fn: #7aa2f7;
|
||||
--tok-built: #2ac3de;
|
||||
--tok-lit: #ff757f;
|
||||
--tok-meta: #e0af68;
|
||||
}
|
||||
|
||||
// ---------- Accent colors ----------
|
||||
// [data-accent] on <html> swaps the accent tokens (accent, accent-strong,
|
||||
// accent-2). Every colour needs a light and a dark variant — the paired
|
||||
// [data-theme='dark'] selector outranks the plain one, so it follows it.
|
||||
$accents: (
|
||||
'purple': ((#7c3aed, #6d28d9, #c026d3), (#a78bfa, #c4b5fd, #e879f9)),
|
||||
'ocean': ((#2563eb, #1d4ed8, #06b6d4), (#60a5fa, #93c5fd, #22d3ee)),
|
||||
'teal': ((#0d9488, #0f766e, #10b981), (#2dd4bf, #5eead4, #34d399)),
|
||||
'forest': ((#16a34a, #15803d, #84cc16), (#4ade80, #86efac, #a3e635)),
|
||||
'amber': ((#d97706, #b45309, #f97316), (#fbbf24, #fcd34d, #fb923c)),
|
||||
'rose': ((#e11d48, #be123c, #ec4899), (#fb7185, #fda4af, #f472b6)),
|
||||
'slate': ((#334155, #1e293b, #64748b), (#94a3b8, #cbd5e1, #7b8aa1)),
|
||||
);
|
||||
|
||||
@each $name, $pair in $accents {
|
||||
$light: list.nth($pair, 1);
|
||||
$dark: list.nth($pair, 2);
|
||||
|
||||
:root[data-accent='#{$name}'] {
|
||||
--accent: #{list.nth($light, 1)};
|
||||
--accent-strong: #{list.nth($light, 2)};
|
||||
--accent-2: #{list.nth($light, 3)};
|
||||
}
|
||||
|
||||
:root[data-theme='dark'][data-accent='#{$name}'] {
|
||||
--accent: #{list.nth($dark, 1)};
|
||||
--accent-strong: #{list.nth($dark, 2)};
|
||||
--accent-2: #{list.nth($dark, 3)};
|
||||
}
|
||||
}
|
||||
|
||||
// the desk is the page itself: no sidebar width to stand aside for
|
||||
@media (max-width: 900px) {
|
||||
:root { --sidebar-w: 0px; --spine-w: 30px; }
|
||||
}
|
||||
10
frontend/app/assets/css/_transitions.scss
Normal file
10
frontend/app/assets/css/_transitions.scss
Normal file
@@ -0,0 +1,10 @@
|
||||
// ---------- Nuxt route transitions ----------
|
||||
.fade-enter-active, .fade-leave-active { transition: opacity 0.16s ease; }
|
||||
|
||||
.fade-enter-from, .fade-leave-to { opacity: 0; }
|
||||
|
||||
// shared between the plain pages — the reader doesn't use it: its pages
|
||||
// move inside the open book (see .book-pane in _book.scss)
|
||||
.page-enter-active, .page-leave-active { transition: opacity 0.16s ease; }
|
||||
|
||||
.page-enter-from, .page-leave-to { opacity: 0; }
|
||||
28
frontend/app/assets/css/main.scss
Normal file
28
frontend/app/assets/css/main.scss
Normal file
@@ -0,0 +1,28 @@
|
||||
// ============================================================
|
||||
// Mathew — the mathematics wiki
|
||||
// Hand-written design system: light/dark themes, layout,
|
||||
// article typography (prose), editor, code + KaTeX styling.
|
||||
// Split into partials, one per section; order mirrors the old CSS.
|
||||
// ============================================================
|
||||
|
||||
@use 'fonts';
|
||||
@use 'tokens';
|
||||
@use 'base';
|
||||
@use 'layout'; // shell, sidebar, account row, collapsed rail
|
||||
@use 'search'; // sidebar bar + the ⌘K popup
|
||||
@use 'settings';
|
||||
@use 'profile';
|
||||
@use 'auth'; // sign-in popup + the editor's gate
|
||||
@use 'buttons'; // .btn family + .icon-btn
|
||||
@use 'home'; // hero, results bar
|
||||
@use 'cards'; // article cards, tags
|
||||
@use 'articles'; // topics index bits
|
||||
@use 'langs'; // badges, chips, version & language menus
|
||||
@use 'states'; // empty, banner, skeleton
|
||||
@use 'admin'; // the accounts dashboard
|
||||
@use 'article'; // article page, ⋮ menu, TOC, recently viewed
|
||||
@use 'prose'; // rendered markdown, highlight.js, KaTeX
|
||||
@use 'editor'; // editor, cheatsheet, confirm, fullscreen
|
||||
@use 'book'; // the reader: an open book of article pages
|
||||
@use 'graph'; // the link map
|
||||
@use 'transitions'; // route fades, scrollbars
|
||||
123
frontend/app/components/AccountActionsMenu.vue
Normal file
123
frontend/app/components/AccountActionsMenu.vue
Normal file
@@ -0,0 +1,123 @@
|
||||
<script setup lang="ts">
|
||||
/* One account's actions on the dashboard, folded into a quiet ⋮: give the admin
|
||||
role or take it back, and delete the account. The menu behaves like the
|
||||
article's (see ArticleActionsMenu) — closed by a click outside, by esc, by
|
||||
navigating, and by search, settings or the profile popup opening over it —
|
||||
and only one row's menu is open at a time, which is what the shared state
|
||||
keys off. */
|
||||
import type { AuthRole } from '~/composables/useAuth'
|
||||
|
||||
const props = defineProps<{
|
||||
/** the account this row belongs to */
|
||||
accountId: string
|
||||
/** whose account it is — the menu says so where the ⋮ waits for a hover */
|
||||
username: string
|
||||
/** what that account may do right now */
|
||||
role: AuthRole
|
||||
/** a request about this account is in flight: the menu waits with it */
|
||||
busy: boolean
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
'set-role': [role: AuthRole]
|
||||
remove: []
|
||||
}>()
|
||||
|
||||
const route = useRoute()
|
||||
const { t } = useI18n()
|
||||
const { openId, show, hide } = useAccountActionsMenu()
|
||||
const { open: searchOpen } = useSearch()
|
||||
const { open: settingsOpen } = useSettings()
|
||||
const { open: profileOpen } = useProfileMenu()
|
||||
|
||||
const open = computed(() => openId.value === props.accountId)
|
||||
|
||||
function toggle() {
|
||||
if (open.value) hide()
|
||||
else show(props.accountId)
|
||||
}
|
||||
|
||||
const wrapEl = ref<HTMLElement | null>(null)
|
||||
|
||||
function onDocClick(e: MouseEvent) {
|
||||
if (open.value && !wrapEl.value?.contains(e.target as Node)) hide()
|
||||
}
|
||||
|
||||
/* Captured so this runs before the page's own Esc handler sees the key: while a
|
||||
menu is open, esc folds it away rather than what the page would do with it. */
|
||||
function onKeydown(e: KeyboardEvent) {
|
||||
if (e.key !== 'Escape' || !open.value) return
|
||||
hide()
|
||||
e.stopPropagation()
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
document.addEventListener('click', onDocClick)
|
||||
window.addEventListener('keydown', onKeydown, true)
|
||||
})
|
||||
onBeforeUnmount(() => {
|
||||
document.removeEventListener('click', onDocClick)
|
||||
window.removeEventListener('keydown', onKeydown, true)
|
||||
})
|
||||
|
||||
watch(() => route.fullPath, hide)
|
||||
watch([searchOpen, settingsOpen, profileOpen], ([search, settings, profile]) => {
|
||||
if (search || settings || profile) hide()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div ref="wrapEl" class="kebab">
|
||||
<button
|
||||
type="button"
|
||||
class="kebab-toggle"
|
||||
:class="{ open }"
|
||||
:aria-expanded="String(open)"
|
||||
aria-haspopup="menu"
|
||||
:title="t('accountActions.forUser', { username })"
|
||||
:aria-label="t('accountActions.aria')"
|
||||
@click="toggle"
|
||||
>
|
||||
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" aria-hidden="true">
|
||||
<circle cx="12" cy="5" r="0.6" />
|
||||
<circle cx="12" cy="12" r="0.6" />
|
||||
<circle cx="12" cy="19" r="0.6" />
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
<div v-if="open" class="kebab-dropdown" role="menu" :aria-label="t('accountActions.aria')">
|
||||
<button
|
||||
type="button"
|
||||
class="kebab-item"
|
||||
role="menuitem"
|
||||
:disabled="busy"
|
||||
@click="hide(); emit('set-role', role === 'admin' ? 'member' : 'admin')"
|
||||
>
|
||||
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
||||
<path d="M12 22s8-4.5 8-10V5.5L12 2 4 5.5V12c0 5.5 8 10 8 10z" />
|
||||
<path v-if="role === 'admin'" d="m9 12 2 2 4-4" />
|
||||
<path v-else d="M9 12h6" />
|
||||
</svg>
|
||||
{{ role === 'admin' ? t('accountActions.removeAdmin') : t('accountActions.makeAdmin') }}
|
||||
</button>
|
||||
|
||||
<div class="kebab-sep" />
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="kebab-item kebab-danger"
|
||||
role="menuitem"
|
||||
:disabled="busy"
|
||||
@click="hide(); emit('remove')"
|
||||
>
|
||||
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
||||
<path d="M3 6h18" />
|
||||
<path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6" />
|
||||
<path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" />
|
||||
<path d="M10 11v6M14 11v6" />
|
||||
</svg>
|
||||
{{ t('common.delete') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
193
frontend/app/components/AppHeader.vue
Normal file
193
frontend/app/components/AppHeader.vue
Normal file
@@ -0,0 +1,193 @@
|
||||
<script setup lang="ts">
|
||||
const { collapsed, toggleSidebar, restoreSidebar } = useSidebar()
|
||||
const { show: openSearch } = useSearch()
|
||||
const { show: openSettings } = useSettings()
|
||||
const { tabs, lastSlug } = useArticleTabs()
|
||||
const { user, isAdmin, signOut } = useAuth()
|
||||
const { show: openSignIn } = useSignInPopup()
|
||||
const { show: openProfile } = useProfileMenu()
|
||||
const { t } = useI18n()
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
|
||||
/* The open articles live in the reading surface: the book ArticleBookStack
|
||||
lays their pages side by side, older ones parked with only their spines
|
||||
showing. The stack stays open all session, but the view of it is only drawn
|
||||
in the reader — so this button is the way back: press it wherever you are
|
||||
(the graph, the list, the editor) and every article you have open comes back
|
||||
into view, stacked as you left it. */
|
||||
const inReader = computed(() => wikiSlugFromPath(route.path) !== null)
|
||||
|
||||
function showOpenArticles() {
|
||||
if (inReader.value) return // the pages are already spread out in view
|
||||
/* turn back to the page that was last in view — every tab knows its own
|
||||
address, language versions included */
|
||||
const target =
|
||||
tabs.value.find((t) => t.slug === lastSlug.value) ?? tabs.value[tabs.value.length - 1]
|
||||
if (target) void router.push(tabHref(target))
|
||||
}
|
||||
|
||||
/* the shortcut hint beside the search bar — "/" keeps focus on the home
|
||||
page's inline box there, so the popup's universal key is Ctrl/⌘+K */
|
||||
const kbdHint = ref('/')
|
||||
onMounted(() => {
|
||||
kbdHint.value = /Mac|iPhone|iPad/i.test(navigator.userAgent) ? '⌘K' : 'Ctrl K'
|
||||
restoreSidebar()
|
||||
})
|
||||
|
||||
/* the account row wears an initial in a circle, so it still reads as a person
|
||||
once the collapsed rail has dropped the name beside it */
|
||||
const initials = computed(() => (user.value?.username.charAt(0) ?? '?').toUpperCase())
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<aside class="site-sidebar" :class="{ collapsed }">
|
||||
<NuxtLink to="/" class="logo" :aria-label="t('sidebar.home')">
|
||||
<span class="logo-mark">∑</span>
|
||||
<span class="hide-collapsed">math<span class="logo-accent">ew</span></span>
|
||||
</NuxtLink>
|
||||
|
||||
<nav class="sidebar-nav">
|
||||
<button
|
||||
type="button"
|
||||
class="sidebar-search"
|
||||
:aria-label="t('common.searchArticles')"
|
||||
@click="openSearch()"
|
||||
>
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true">
|
||||
<circle cx="11" cy="11" r="7" />
|
||||
<path d="m20 20-3.2-3.2" />
|
||||
</svg>
|
||||
<span class="sidebar-search-label hide-collapsed">{{ t('sidebar.search') }}</span>
|
||||
<kbd class="kbd-hint hide-collapsed">{{ kbdHint }}</kbd>
|
||||
</button>
|
||||
|
||||
<button
|
||||
v-if="tabs.length"
|
||||
type="button"
|
||||
class="nav-link sidebar-open"
|
||||
:class="{ 'is-current': inReader }"
|
||||
:aria-label="t('sidebar.openAria', tabs.length)"
|
||||
:title="t('sidebar.openTitle', tabs.length)"
|
||||
@click="showOpenArticles()"
|
||||
>
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
||||
<path d="M12 2 2 7l10 5 10-5-10-5z" />
|
||||
<path d="m2 12 10 5 10-5" />
|
||||
<path d="m2 17 10 5 10-5" />
|
||||
</svg>
|
||||
<span class="hide-collapsed">{{ t('sidebar.open') }}</span>
|
||||
<span class="tabs-count hide-collapsed">{{ tabs.length }}</span>
|
||||
</button>
|
||||
|
||||
<NuxtLink to="/articles" class="nav-link" :title="t('sidebar.articles')">
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
||||
<path d="M4 19.5A2.5 2.5 0 0 1 6.5 17H20" />
|
||||
<path d="M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z" />
|
||||
</svg>
|
||||
<span class="hide-collapsed">{{ t('sidebar.articles') }}</span>
|
||||
</NuxtLink>
|
||||
<NuxtLink to="/graph" class="nav-link" :title="t('sidebar.graph')">
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
||||
<circle cx="18" cy="5" r="3" />
|
||||
<circle cx="6" cy="12" r="3" />
|
||||
<circle cx="18" cy="19" r="3" />
|
||||
<path d="m8.6 10.5 6.8-4M8.6 13.5l6.8 4" />
|
||||
</svg>
|
||||
<span class="hide-collapsed">{{ t('sidebar.graph') }}</span>
|
||||
</NuxtLink>
|
||||
<NuxtLink
|
||||
v-if="isAdmin"
|
||||
to="/admin"
|
||||
class="nav-link"
|
||||
:title="t('sidebar.adminHint')"
|
||||
>
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
||||
<path d="M12 22s8-4.5 8-10V5.5L12 2 4 5.5V12c0 5.5 8 10 8 10z" />
|
||||
<path d="m9 12 2 2 4-4" />
|
||||
</svg>
|
||||
<span class="hide-collapsed">{{ t('sidebar.admin') }}</span>
|
||||
</NuxtLink>
|
||||
<NuxtLink to="/new" class="btn btn-primary btn-sm" :title="t('sidebar.newArticle')">
|
||||
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round">
|
||||
<path d="M12 5v14M5 12h14" />
|
||||
</svg>
|
||||
<span class="hide-collapsed">{{ t('sidebar.newArticle') }}</span>
|
||||
</NuxtLink>
|
||||
</nav>
|
||||
|
||||
<div class="sidebar-footer">
|
||||
<!-- who is using the wiki. Reading needs no account, so a visitor is given
|
||||
the door in; a signed-in person sees who writes as themselves and can
|
||||
open their profile — the picture, the account, the way out. -->
|
||||
<div v-if="user" class="account-row">
|
||||
<button
|
||||
type="button"
|
||||
class="account-open"
|
||||
:title="t('sidebar.signedInAs', { name: user.username })"
|
||||
@click="openProfile()"
|
||||
>
|
||||
<span class="account-avatar" aria-hidden="true">
|
||||
<img v-if="user.avatar" :src="user.avatar" alt="" />
|
||||
<template v-else>{{ initials }}</template>
|
||||
</span>
|
||||
<span class="hide-collapsed account-name">{{ user.username }}</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="account-exit hide-collapsed"
|
||||
:aria-label="t('common.signOut')"
|
||||
:title="t('common.signOut')"
|
||||
@click="signOut()"
|
||||
>
|
||||
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
||||
<path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4" />
|
||||
<path d="m16 17 5-5-5-5" />
|
||||
<path d="M21 12H9" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
<button
|
||||
v-else
|
||||
type="button"
|
||||
class="icon-btn"
|
||||
:title="t('sidebar.signInHint')"
|
||||
@click="openSignIn()"
|
||||
>
|
||||
<svg width="17" height="17" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
||||
<circle cx="8.5" cy="15.5" r="4" />
|
||||
<path d="m11.6 12.4 8.4-8.4 2 2-2 2 1.5 1.5-2 2-1.5-1.5-1.9 1.9" />
|
||||
</svg>
|
||||
<span class="hide-collapsed">{{ t('auth.signin') }}</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="icon-btn"
|
||||
:aria-label="t('settings.title')"
|
||||
:title="t('settings.title')"
|
||||
@click="openSettings()"
|
||||
>
|
||||
<svg width="17" height="17" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
||||
<circle cx="12" cy="12" r="3" />
|
||||
<path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1Z" />
|
||||
</svg>
|
||||
<span class="hide-collapsed">{{ t('settings.title') }}</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="panel-icon-btn sidebar-collapse-btn"
|
||||
:aria-label="collapsed ? t('sidebar.expand') : t('sidebar.collapse')"
|
||||
:title="collapsed ? t('sidebar.expand') : t('sidebar.collapse')"
|
||||
@click="toggleSidebar()"
|
||||
>
|
||||
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
||||
<path d="m15 18-6-6 6-6" />
|
||||
</svg>
|
||||
<span class="hide-collapsed">{{ t('sidebar.collapseLabel') }}</span>
|
||||
</button>
|
||||
</div>
|
||||
</aside>
|
||||
</template>
|
||||
127
frontend/app/components/ArticleActionsMenu.vue
Normal file
127
frontend/app/components/ArticleActionsMenu.vue
Normal file
@@ -0,0 +1,127 @@
|
||||
<script setup lang="ts">
|
||||
/* The article's actions folded into one ⋮ button: Edit, the language menu,
|
||||
and Delete — so the title row keeps its space to itself. The menu behaves
|
||||
like the app's other popups: closed by a click outside, by esc (unless the
|
||||
language submenu is open, since that claims the key first), by navigating,
|
||||
and by search or settings opening over it. The language menu rides inside
|
||||
as a menu item of its own — its list drops over the rest of this menu. */
|
||||
import type { ArticleVersion } from './ArticleCard.vue'
|
||||
|
||||
defineProps<{
|
||||
/** the article the versions belong to — its canonical slug */
|
||||
identity: string
|
||||
versions: ArticleVersion[]
|
||||
/** the version in view and the language it is written in */
|
||||
currentSlug: string
|
||||
language: string
|
||||
/** the slug the editor answers to */
|
||||
editorSlug: string
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
remove: []
|
||||
}>()
|
||||
|
||||
const route = useRoute()
|
||||
const { t } = useI18n()
|
||||
const { open, hide } = useArticleActionsMenu()
|
||||
const { open: langMenuOpen } = useLanguageMenu()
|
||||
const { open: searchOpen } = useSearch()
|
||||
const { open: settingsOpen } = useSettings()
|
||||
const { open: profileOpen } = useProfileMenu()
|
||||
|
||||
function toggle() {
|
||||
open.value = !open.value
|
||||
}
|
||||
|
||||
const wrapEl = ref<HTMLElement | null>(null)
|
||||
|
||||
function onDocClick(e: MouseEvent) {
|
||||
if (open.value && !wrapEl.value?.contains(e.target as Node)) hide()
|
||||
}
|
||||
|
||||
/* Captured so this runs before the book's own Esc handler sees the key: while
|
||||
the menu is open, esc folds it away instead of closing the page. The
|
||||
language submenu sits on top of this menu, so it gets the key first. */
|
||||
function onKeydown(e: KeyboardEvent) {
|
||||
if (e.key !== 'Escape' || !open.value) return
|
||||
if (langMenuOpen.value) return
|
||||
hide()
|
||||
e.stopPropagation()
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
document.addEventListener('click', onDocClick)
|
||||
window.addEventListener('keydown', onKeydown, true)
|
||||
})
|
||||
onBeforeUnmount(() => {
|
||||
document.removeEventListener('click', onDocClick)
|
||||
window.removeEventListener('keydown', onKeydown, true)
|
||||
})
|
||||
|
||||
watch(() => route.fullPath, hide)
|
||||
watch([searchOpen, settingsOpen, profileOpen], ([search, settings, profile]) => {
|
||||
if (search || settings || profile) hide()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div ref="wrapEl" class="kebab">
|
||||
<button
|
||||
type="button"
|
||||
class="kebab-toggle"
|
||||
:class="{ open }"
|
||||
:aria-expanded="String(open)"
|
||||
:title="t('articleActions.aria')"
|
||||
:aria-label="t('articleActions.aria')"
|
||||
@click="toggle"
|
||||
>
|
||||
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" aria-hidden="true">
|
||||
<circle cx="12" cy="5" r="0.6" />
|
||||
<circle cx="12" cy="12" r="0.6" />
|
||||
<circle cx="12" cy="19" r="0.6" />
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
<div v-if="open" class="kebab-dropdown" role="menu" :aria-label="t('articleActions.aria')">
|
||||
<NuxtLink
|
||||
:to="{ path: `/wiki/${editorSlug}/edit`, query: { lang: language } }"
|
||||
class="kebab-item"
|
||||
role="menuitem"
|
||||
@click="hide"
|
||||
>
|
||||
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
||||
<path d="M12 20h9M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z" />
|
||||
</svg>
|
||||
{{ t('common.edit') }}
|
||||
</NuxtLink>
|
||||
|
||||
<div class="kebab-sep" />
|
||||
|
||||
<ArticleLanguageMenu
|
||||
:identity="identity"
|
||||
:versions="versions"
|
||||
:current-slug="currentSlug"
|
||||
:language="language"
|
||||
:editor-slug="editorSlug"
|
||||
/>
|
||||
|
||||
<div class="kebab-sep" />
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="kebab-item kebab-danger"
|
||||
role="menuitem"
|
||||
@click="hide(); emit('remove')"
|
||||
>
|
||||
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
||||
<path d="M3 6h18" />
|
||||
<path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6" />
|
||||
<path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" />
|
||||
<path d="M10 11v6M14 11v6" />
|
||||
</svg>
|
||||
{{ t('common.delete') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
257
frontend/app/components/ArticleBookStack.vue
Normal file
257
frontend/app/components/ArticleBookStack.vue
Normal file
@@ -0,0 +1,257 @@
|
||||
<script setup lang="ts">
|
||||
/* The reading surface: an open book of the articles from this session. Each
|
||||
one is a page laid out beside the last, and you move along them sideways.
|
||||
A page turned to slides over the older ones, which park along the left
|
||||
edge with only their spines showing; click anywhere on a page — spine or
|
||||
body — to turn back to it, or × to close it. Routes stay the source of
|
||||
truth — every page is a plain /wiki/<slug> URL — and useArticleTabs keeps
|
||||
the stack of pages.
|
||||
|
||||
Pages further along the book than the one in view wait off the right edge
|
||||
of the desk, where you would have to scroll sideways to reach them. Their
|
||||
spines are copied into a stack docked at the right edge of the desk instead
|
||||
— turning one takes you to the page as if you had scrolled to it — and a
|
||||
spine leaves the stack as its page is brought into view.
|
||||
|
||||
Narrow screens fold the book to the one page in view, with its neighbours
|
||||
as chips along the top. */
|
||||
|
||||
const api = `${useRuntimeConfig().public.apiBase}/api`
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const { t } = useI18n()
|
||||
|
||||
const { tabs, closeTab } = useArticleTabs()
|
||||
const { load, forget } = useArticleLibrary()
|
||||
const { open: searchOpen } = useSearch()
|
||||
const { open: settingsOpen } = useSettings()
|
||||
const { open: profileOpen } = useProfileMenu()
|
||||
const { open: langMenuOpen } = useLanguageMenu()
|
||||
const { open: actionsMenuOpen } = useArticleActionsMenu()
|
||||
const { collapsed } = useSidebar()
|
||||
|
||||
const activeTab = computed(() => tabAt(tabs.value, route.path))
|
||||
const activeSlug = computed(() => activeTab.value?.slug ?? null)
|
||||
const visible = computed(() => isReaderPath(route.path) && tabs.value.length > 0)
|
||||
|
||||
const trackEl = ref<HTMLElement | null>(null)
|
||||
|
||||
/** Whether the book is open flat on the desk (wide) or folded (narrow). */
|
||||
function liesFlat() {
|
||||
return import.meta.client && !window.matchMedia('(max-width: 900px)').matches
|
||||
}
|
||||
|
||||
/** Which page of the book is the one in view, or -1 when the route names
|
||||
* none of them. Only the pages beyond it can be waiting for you. */
|
||||
const openIndex = computed(() => {
|
||||
const slug = activeSlug.value
|
||||
return slug === null ? -1 : tabs.value.findIndex((t) => t.slug === slug)
|
||||
})
|
||||
|
||||
/**
|
||||
* Bring the page in view back to its place in the stack. Pages are laid out
|
||||
* a page-width apart and each one parks `--i` spines from the left edge, so
|
||||
* scrolling to i * (page width − spine width) sets the whole row: older
|
||||
* pages fanned into spines on the left, the rest waiting off the right edge.
|
||||
*/
|
||||
async function alignToActive(behavior: ScrollBehavior = 'smooth') {
|
||||
await nextTick()
|
||||
const track = trackEl.value
|
||||
const slug = activeSlug.value
|
||||
if (!track || !slug || !liesFlat()) return
|
||||
|
||||
const page = track.querySelector<HTMLElement>(`[data-slug="${CSS.escape(slug)}"]`)
|
||||
const i = Number(page?.dataset.index)
|
||||
if (!page || !Number.isFinite(i)) return
|
||||
|
||||
const spine = parseFloat(getComputedStyle(track).getPropertyValue('--spine-w')) || 0
|
||||
track.scrollTo({ left: i * (page.offsetWidth - spine), behavior })
|
||||
measureDock()
|
||||
}
|
||||
|
||||
/* ---------- the dock: pages waiting beyond the right edge of the desk -----
|
||||
A page further along the book than the one in view has its spine off the
|
||||
right hand side of the screen, and only a sideways scroll reaches it. While
|
||||
it is there its spine is kept at the right edge of the desk, so the page is
|
||||
a click away rather than a drag away. Which pages are out there is measured
|
||||
off the row, not guessed at: slide the book and a spine leaves the stack as
|
||||
its page comes into view, and joins it again as the page slides out. */
|
||||
|
||||
/** The slugs of the pages whose spines are in the dock. */
|
||||
const waitingSlugs = ref<string[]>([])
|
||||
/** Those pages, in the order they were opened. */
|
||||
const waiting = computed(() => tabs.value.filter((t) => waitingSlugs.value.includes(t.slug)))
|
||||
|
||||
/**
|
||||
* Fill the dock with the pages beyond the one in view whose spines have no
|
||||
* room left on the desk. A page keeps its place while it straddles the edge,
|
||||
* so a page sliding past doesn't flicker in and out of the stack.
|
||||
*/
|
||||
function measureDock() {
|
||||
const track = trackEl.value
|
||||
const open = openIndex.value
|
||||
if (!track || open === -1 || !liesFlat()) {
|
||||
waitingSlugs.value = []
|
||||
return
|
||||
}
|
||||
|
||||
const edge = track.getBoundingClientRect().right
|
||||
const spine = parseFloat(getComputedStyle(track).getPropertyValue('--spine-w')) || 0
|
||||
const held = new Set(waitingSlugs.value)
|
||||
for (const page of Array.from(track.querySelectorAll<HTMLElement>('.book-pane'))) {
|
||||
const i = Number(page.dataset.index)
|
||||
const slug = page.dataset.slug
|
||||
if (!slug || !Number.isFinite(i) || i <= open) continue
|
||||
const left = page.getBoundingClientRect().left
|
||||
if (left > edge - 6) held.add(slug)
|
||||
else if (left < edge - spine - 10) held.delete(slug)
|
||||
}
|
||||
waitingSlugs.value = tabs.value.filter((t, i) => i > open && held.has(t.slug)).map((t) => t.slug)
|
||||
}
|
||||
|
||||
/* the row moves on scroll, so the dock is measured once a frame while it does */
|
||||
let measuring = 0
|
||||
function watchDock() {
|
||||
if (measuring) return
|
||||
measuring = requestAnimationFrame(() => {
|
||||
measuring = 0
|
||||
measureDock()
|
||||
})
|
||||
}
|
||||
onBeforeUnmount(() => cancelAnimationFrame(measuring))
|
||||
|
||||
/* turning to an article slides the book round to it */
|
||||
watch(activeSlug, () => void alignToActive('smooth'))
|
||||
/* and the row changing shape — however it changed — changes which pages are
|
||||
waiting out beyond the edge of the desk */
|
||||
watch(tabs, () => void nextTick(measureDock))
|
||||
|
||||
/* a page opened or closed changes how wide every page is — settle the row
|
||||
again so the one in view doesn't drift */
|
||||
watch(
|
||||
() => tabs.value.length,
|
||||
() => void alignToActive('auto')
|
||||
)
|
||||
|
||||
/* pages are sized against the window, so keep them honest as it moves */
|
||||
function onResize() {
|
||||
void alignToActive('auto')
|
||||
measureDock()
|
||||
}
|
||||
onMounted(() => {
|
||||
void alignToActive('auto')
|
||||
void nextTick(measureDock)
|
||||
window.addEventListener('resize', onResize)
|
||||
})
|
||||
onBeforeUnmount(() => window.removeEventListener('resize', onResize))
|
||||
|
||||
/* collapsing the sidebar moves the reading surface's left edge, which
|
||||
resizes every page — settle the row again once the rail has finished
|
||||
sliding */
|
||||
watch(collapsed, () => {
|
||||
setTimeout(() => void alignToActive('auto'), 260)
|
||||
})
|
||||
|
||||
/* every page of the book should hold its article: pull the ones the route
|
||||
host hasn't already written in (background pages, client-side only) */
|
||||
watch(
|
||||
tabs,
|
||||
() => {
|
||||
for (const t of tabs.value) void load(t.slug)
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
function turnTo(slug: string) {
|
||||
const tab = tabs.value.find((t) => t.slug === slug)
|
||||
if (tab && slug !== activeSlug.value) void router.push(tabHref(tab))
|
||||
}
|
||||
|
||||
async function removeArticle(slug: string) {
|
||||
const title = tabs.value.find((t) => t.slug === slug)?.title ?? slug
|
||||
if (!window.confirm(t('book.deleteConfirm', { title }))) return
|
||||
try {
|
||||
await $fetch(`${api}/articles/slug/${encodeURIComponent(slug)}`, { method: 'DELETE' })
|
||||
forget(slug)
|
||||
closeTab(slug)
|
||||
} catch {
|
||||
window.alert(t('book.deleteFailed'))
|
||||
}
|
||||
}
|
||||
|
||||
/* Esc closes the page in view — unless a popup is open, since those
|
||||
claim the key first */
|
||||
function onGlobalKeydown(e: KeyboardEvent) {
|
||||
if (e.key !== 'Escape') return
|
||||
if (searchOpen.value || settingsOpen.value || profileOpen.value || langMenuOpen.value || actionsMenuOpen.value)
|
||||
return
|
||||
const current = tabAt(tabs.value, route.path)?.slug
|
||||
if (current) closeTab(current)
|
||||
}
|
||||
onMounted(() => window.addEventListener('keydown', onGlobalKeydown))
|
||||
onBeforeUnmount(() => window.removeEventListener('keydown', onGlobalKeydown))
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="visible" class="book-layer" :style="{ '--panes': tabs.length }">
|
||||
<nav
|
||||
v-if="tabs.length > 1"
|
||||
class="book-chips"
|
||||
role="tablist"
|
||||
:aria-label="t('book.openAria')"
|
||||
>
|
||||
<div
|
||||
v-for="tab in tabs"
|
||||
:key="tab.slug"
|
||||
class="book-chip"
|
||||
:class="{ active: tab.slug === activeSlug }"
|
||||
role="tab"
|
||||
tabindex="0"
|
||||
:aria-selected="tab.slug === activeSlug"
|
||||
:title="t('book.chipHint', { title: tab.title })"
|
||||
@click="turnTo(tab.slug)"
|
||||
@keydown.enter.prevent="turnTo(tab.slug)"
|
||||
>
|
||||
<span class="chip-title">{{ tab.title }}</span>
|
||||
<button type="button" class="chip-close" :aria-label="t('common.closeTab')" @click.stop="closeTab(tab.slug)">
|
||||
<svg width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.8" stroke-linecap="round" aria-hidden="true">
|
||||
<path d="M6 6l12 12M18 6L6 18" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div ref="trackEl" class="book-track" @scroll.passive="watchDock">
|
||||
<ArticlePane
|
||||
v-for="(tab, i) in tabs"
|
||||
:key="tab.slug"
|
||||
:slug="tab.slug"
|
||||
:index="i"
|
||||
:active="tab.slug === activeSlug"
|
||||
@activate="turnTo(tab.slug)"
|
||||
@close="closeTab(tab.slug)"
|
||||
@remove="removeArticle(tab.slug)"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<nav v-if="waiting.length" class="book-dock" :aria-label="t('book.dockAria')">
|
||||
<div
|
||||
v-for="tab in waiting"
|
||||
:key="tab.slug"
|
||||
class="dock-spine"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
:title="t('book.dockHint', { title: tab.title })"
|
||||
@click="turnTo(tab.slug)"
|
||||
@keydown.enter.prevent="turnTo(tab.slug)"
|
||||
>
|
||||
<button type="button" class="spine-close" :aria-label="t('common.closeTab')" @click.stop="closeTab(tab.slug)">
|
||||
<svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.6" stroke-linecap="round" aria-hidden="true">
|
||||
<path d="M6 6l12 12M18 6L6 18" />
|
||||
</svg>
|
||||
</button>
|
||||
<span class="spine-title">{{ tab.title }}</span>
|
||||
</div>
|
||||
</nav>
|
||||
</div>
|
||||
</template>
|
||||
77
frontend/app/components/ArticleCard.vue
Normal file
77
frontend/app/components/ArticleCard.vue
Normal file
@@ -0,0 +1,77 @@
|
||||
<script setup lang="ts">
|
||||
/* One language version of an article, as the version switcher lists them. */
|
||||
export interface ArticleVersion {
|
||||
language: string
|
||||
slug: string
|
||||
title: string
|
||||
updatedAt?: string
|
||||
}
|
||||
|
||||
export interface ArticleMeta {
|
||||
_id: string
|
||||
slug: string
|
||||
title: string
|
||||
tags?: string[]
|
||||
language?: string
|
||||
/* set on translations: the canonical (original) version's slug */
|
||||
baseSlug?: string | null
|
||||
/* every language version the article exists in, from the single-article GET */
|
||||
versions?: ArticleVersion[]
|
||||
createdAt?: string
|
||||
updatedAt?: string
|
||||
}
|
||||
|
||||
const props = defineProps<{ article: ArticleMeta }>()
|
||||
|
||||
const { t, locale } = useI18n()
|
||||
|
||||
/* shown only when an article steps off the English default — a quiet badge
|
||||
so the shelf's other languages are visible at a glance; when the article
|
||||
exists in several languages, its codes ride together instead */
|
||||
const language = computed(() => articleLanguage(props.article))
|
||||
const languageLabel = computed(() => languageName(language.value))
|
||||
const langs = computed(() => props.article.versions ?? [])
|
||||
const multiLang = computed(() => langs.value.length > 1)
|
||||
const langCodes = computed(() => langs.value.map((v) => v.language.toUpperCase()).join(' · '))
|
||||
const langNames = computed(() => langs.value.map((v) => languageName(v.language)).join(', '))
|
||||
/* where the card leads: the language address of the version it shows */
|
||||
const href = computed(() =>
|
||||
versionHref(identityOf(props.article), { language: language.value, slug: props.article.slug })
|
||||
)
|
||||
|
||||
const updated = computed(() => {
|
||||
const d = props.article.updatedAt ? new Date(props.article.updatedAt) : null
|
||||
if (!d || Number.isNaN(d.getTime())) return ''
|
||||
return d.toLocaleDateString(locale.value, { year: 'numeric', month: 'short', day: 'numeric' })
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<NuxtLink :to="href" class="article-card">
|
||||
<div class="card-top">
|
||||
<span class="card-kicker">{{ article.baseSlug ? t('card.kickerTranslation') : t('card.kickerArticle') }}</span>
|
||||
<span v-if="multiLang" class="card-langs" :title="t('card.existsIn', { names: langNames })">
|
||||
<svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
||||
<circle cx="12" cy="12" r="10" />
|
||||
<path d="M2 12h20" />
|
||||
<path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z" />
|
||||
</svg>
|
||||
{{ langCodes }}
|
||||
</span>
|
||||
<span
|
||||
v-else-if="language !== 'en'"
|
||||
class="lang-badge"
|
||||
:title="t('common.writtenIn', { lang: languageLabel })"
|
||||
>{{ languageLabel }}</span
|
||||
>
|
||||
</div>
|
||||
<h3 class="card-title" :lang="language">{{ article.title }}</h3>
|
||||
<div v-if="article.tags?.length" class="tags">
|
||||
<span v-for="tag in article.tags.slice(0, 3)" :key="tag" class="tag">{{ tag }}</span>
|
||||
</div>
|
||||
<div class="card-meta">
|
||||
<span>{{ href }}</span>
|
||||
<span v-if="updated">{{ t('card.updated', { date: updated }) }}</span>
|
||||
</div>
|
||||
</NuxtLink>
|
||||
</template>
|
||||
786
frontend/app/components/ArticleForm.vue
Normal file
786
frontend/app/components/ArticleForm.vue
Normal file
@@ -0,0 +1,786 @@
|
||||
<script setup lang="ts">
|
||||
import type { ArticleMeta } from './ArticleCard.vue'
|
||||
|
||||
const props = defineProps<{
|
||||
mode: 'create' | 'edit'
|
||||
article?: ArticleMeta & { content?: string }
|
||||
/* Translating: the version being translated. The form opens with its text
|
||||
and publishes a new language version of the same article. */
|
||||
translateFrom?: ArticleMeta & { content?: string }
|
||||
/* Languages the article being translated already exists in */
|
||||
takenLanguages?: string[]
|
||||
}>()
|
||||
|
||||
const api = `${useRuntimeConfig().public.apiBase}/api`
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
/* Writing is the one thing on this page that takes an account: the save carries
|
||||
the session token, and a save the API refuses is the editor's own signal that
|
||||
the session has gone while this draft was open. */
|
||||
const { authHeaders } = useAuth()
|
||||
const { show: openSignIn } = useSignInPopup()
|
||||
const { t } = useI18n()
|
||||
|
||||
const original = props.translateFrom ?? null
|
||||
/* the version group the new document joins, shared by every translation */
|
||||
const baseSlug = original ? original.baseSlug || original.slug : ''
|
||||
|
||||
/* an edit is always an article — every language version of it answers to the
|
||||
same identity, which is what its reader and editor addresses speak */
|
||||
const isVersioned = computed(() => props.mode === 'edit' && !!props.article)
|
||||
const identity = props.article ? props.article.baseSlug || props.article.slug : ''
|
||||
|
||||
/* versions under edit -------------------------------------------------
|
||||
Editing an article happens one language at a time: each version keeps its
|
||||
own draft beside the others, so typing French does not overwrite English —
|
||||
switching turns the page, it does not clear it. */
|
||||
interface VersionDraft {
|
||||
language: string
|
||||
/** saved document's slug; null for a version not written yet */
|
||||
slug: string | null
|
||||
title: string
|
||||
tagsText: string
|
||||
content: string
|
||||
/** the text as it was loaded or last saved — what "dirty" compares against */
|
||||
saved: { title: string; tagsText: string; content: string }
|
||||
/** whether the version's full text has arrived from the API */
|
||||
loaded: boolean
|
||||
}
|
||||
|
||||
const drafts = ref<Record<string, VersionDraft>>({})
|
||||
|
||||
function seedDraft(language: string, slug: string | null, doc?: ArticleMeta & { content?: string }): VersionDraft {
|
||||
return {
|
||||
language,
|
||||
slug,
|
||||
title: doc?.title ?? '',
|
||||
tagsText: (doc?.tags ?? []).join(', '),
|
||||
content: doc?.content ?? '',
|
||||
saved: {
|
||||
title: doc?.title ?? '',
|
||||
tagsText: (doc?.tags ?? []).join(', '),
|
||||
content: doc?.content ?? '',
|
||||
},
|
||||
loaded: !!doc,
|
||||
}
|
||||
}
|
||||
|
||||
if (isVersioned.value && props.article) {
|
||||
const doc = props.article
|
||||
const list = doc.versions?.length
|
||||
? doc.versions
|
||||
: [{ language: doc.language ?? 'en', slug: doc.slug, title: doc.title }]
|
||||
for (const v of list) {
|
||||
/* the document already in hand needs no fetch; the rest arrive on demand
|
||||
with only their titles known up front — enough to fill the field while
|
||||
the text comes over */
|
||||
const draft = seedDraft(v.language, v.slug, v.slug === doc.slug ? doc : undefined)
|
||||
if (!draft.loaded && v.title) draft.title = v.title
|
||||
drafts.value[v.language] = draft
|
||||
}
|
||||
}
|
||||
|
||||
/* the language this editor is showing — its address is ?lang= on the route */
|
||||
const initialLang = String(route.query.lang ?? '').trim().toLowerCase()
|
||||
const activeLang = ref(
|
||||
drafts.value[initialLang]?.language ?? props.article?.language ?? 'en'
|
||||
)
|
||||
|
||||
/* one draft is in view and edited through these; the rest wait in `drafts` */
|
||||
const title = ref(activeDraft()?.title ?? original?.title ?? '')
|
||||
const tagsText = ref(activeDraft()?.tagsText ?? (original?.tags ?? []).join(', '))
|
||||
const content = ref(activeDraft()?.content ?? original?.content ?? '')
|
||||
/* the language a fresh (non-versioned) article is written in — the reader's
|
||||
language menu asks for one on the route (/new?translate=x&lang=de): start
|
||||
there, unless the article is already written in it */
|
||||
const requestedLang = String(route.query.lang ?? '').trim().toLowerCase()
|
||||
const preselected =
|
||||
LANGUAGES.some((l) => l.code === requestedLang) &&
|
||||
!(props.takenLanguages ?? []).includes(requestedLang)
|
||||
? requestedLang
|
||||
: ''
|
||||
const language = ref(
|
||||
props.article?.language?.trim().toLowerCase() ||
|
||||
preselected ||
|
||||
nextFreeLanguage(props.takenLanguages ?? [])
|
||||
)
|
||||
|
||||
function activeDraft(): VersionDraft | undefined {
|
||||
return drafts.value[activeLang.value]
|
||||
}
|
||||
|
||||
const versionList = computed(() => Object.values(drafts.value))
|
||||
const freeLanguages = computed(() => LANGUAGES.filter((l) => !drafts.value[l.code]))
|
||||
|
||||
function draftCurrent(d: VersionDraft) {
|
||||
return d.language === activeLang.value
|
||||
? { title: title.value, tagsText: tagsText.value, content: content.value }
|
||||
: { title: d.title, tagsText: d.tagsText, content: d.content }
|
||||
}
|
||||
|
||||
function draftChanged(d: VersionDraft) {
|
||||
if (!d.loaded) return false
|
||||
return JSON.stringify(draftCurrent(d)) !== JSON.stringify(d.saved)
|
||||
}
|
||||
|
||||
const dirtyCount = computed(
|
||||
() => (isVersioned.value ? versionList.value.filter(draftChanged).length : singleDirty.value ? 1 : 0)
|
||||
)
|
||||
|
||||
/* fetch a version's text the first time the editor turns to it */
|
||||
async function hydrate(d: VersionDraft) {
|
||||
if (!d.slug) return
|
||||
/* remember what the fields held on arrival: if anything was typed while the
|
||||
fetch was on its way, the typing wins over what comes back */
|
||||
const untouched = { title: title.value, tagsText: tagsText.value, content: content.value }
|
||||
try {
|
||||
const doc = await $fetch<ArticleMeta & { content?: string }>(
|
||||
`${api}/articles/slug/${encodeURIComponent(d.slug)}`
|
||||
)
|
||||
d.title = doc.title ?? ''
|
||||
d.tagsText = (doc.tags ?? []).join(', ')
|
||||
d.content = doc.content ?? ''
|
||||
d.saved = { title: d.title, tagsText: d.tagsText, content: d.content }
|
||||
d.loaded = true
|
||||
/* if the editor still rests on this version, and nothing was typed into
|
||||
it since, show what arrived */
|
||||
if (
|
||||
d.language === activeLang.value &&
|
||||
JSON.stringify(untouched) ===
|
||||
JSON.stringify({ title: title.value, tagsText: tagsText.value, content: content.value })
|
||||
) {
|
||||
title.value = d.title
|
||||
tagsText.value = d.tagsText
|
||||
content.value = d.content
|
||||
}
|
||||
} catch {
|
||||
/* an unreadable version stays a blank page; saving will say why it failed */
|
||||
}
|
||||
}
|
||||
|
||||
function putDraftFields(d: VersionDraft | undefined) {
|
||||
if (!d) return
|
||||
title.value = d.title
|
||||
tagsText.value = d.tagsText
|
||||
content.value = d.content
|
||||
}
|
||||
|
||||
function stashActive() {
|
||||
const d = activeDraft()
|
||||
if (!d || !d.loaded) return
|
||||
d.title = title.value
|
||||
d.tagsText = tagsText.value
|
||||
d.content = content.value
|
||||
}
|
||||
|
||||
async function switchLang(lang: string) {
|
||||
if (lang === activeLang.value) return
|
||||
stashActive()
|
||||
activeLang.value = lang
|
||||
const d = drafts.value[lang]
|
||||
putDraftFields(d)
|
||||
if (d && !d.loaded) await hydrate(d)
|
||||
void router.replace({ query: { ...route.query, lang } })
|
||||
}
|
||||
|
||||
/* the language dropdown beside the chips -------------------------------- */
|
||||
const addOpen = ref(false)
|
||||
const addWrapEl = ref<HTMLElement | null>(null)
|
||||
|
||||
function onDocClick(e: MouseEvent) {
|
||||
if (addOpen.value && !addWrapEl.value?.contains(e.target as Node)) addOpen.value = false
|
||||
}
|
||||
onMounted(() => document.addEventListener('click', onDocClick))
|
||||
onBeforeUnmount(() => document.removeEventListener('click', onDocClick))
|
||||
|
||||
function addLanguage(code: string) {
|
||||
addOpen.value = false
|
||||
stashActive()
|
||||
/* a fresh version starts empty under the hood and carries the article's
|
||||
tags across — they describe the topic, not the language */
|
||||
drafts.value[code] = seedDraft(code, null, {
|
||||
_id: '',
|
||||
slug: '',
|
||||
title: '',
|
||||
tags: tagsText.value
|
||||
.split(',')
|
||||
.map((t) => t.trim().toLowerCase())
|
||||
.filter(Boolean),
|
||||
content: '',
|
||||
} as ArticleMeta)
|
||||
activeLang.value = code
|
||||
title.value = ''
|
||||
tagsText.value = drafts.value[code]!.tagsText
|
||||
content.value = ''
|
||||
void router.replace({ query: { ...route.query, lang: code } })
|
||||
}
|
||||
|
||||
/* the version in view is fetched on demand, even on first arrival (?lang=fr) */
|
||||
onMounted(() => {
|
||||
const d = activeDraft()
|
||||
if (isVersioned.value && d && !d.loaded) void hydrate(d)
|
||||
})
|
||||
|
||||
const languages = computed(() =>
|
||||
LANGUAGES.map((l) => ({
|
||||
...l,
|
||||
taken: !!original && (props.takenLanguages ?? []).includes(l.code),
|
||||
}))
|
||||
)
|
||||
|
||||
function slugifyText(text: string): string {
|
||||
return text
|
||||
.toLowerCase()
|
||||
.trim()
|
||||
.replace(/[^\w\s-]/g, '')
|
||||
.replace(/[\s_]+/g, '-')
|
||||
.replace(/-+/g, '-')
|
||||
.replace(/^-|-$/g, '')
|
||||
}
|
||||
|
||||
/* the address being edited or published: versions live at /wiki/<lang>/<slug>,
|
||||
the canonical article at /wiki/<slug> — where a canonical retitle moves it */
|
||||
const slugPreview = computed(() => {
|
||||
if (isVersioned.value) {
|
||||
const d = activeDraft()
|
||||
if (d && d.slug && d.slug !== identity) return `/wiki/${d.language}/${identity}`
|
||||
return `/wiki/${slugifyText(title.value) || savedSlug}`
|
||||
}
|
||||
if (original) return `/wiki/${language.value}/${baseSlug}`
|
||||
return `/wiki/${slugifyText(title.value) || '…'}`
|
||||
})
|
||||
|
||||
const savedSlug = props.article?.slug ?? ''
|
||||
|
||||
/* dirty tracking -------------------------------------------------
|
||||
A versioned edit is dirty when any version's text differs from what it was
|
||||
loaded or saved as; the plain create form compares against what it opened
|
||||
with. */
|
||||
interface FormState {
|
||||
title: string
|
||||
tagsText: string
|
||||
content: string
|
||||
}
|
||||
|
||||
function currentState(): FormState {
|
||||
return { title: title.value, tagsText: tagsText.value, content: content.value }
|
||||
}
|
||||
|
||||
const savedState = ref<FormState>(currentState())
|
||||
const singleDirty = computed(
|
||||
() => !isVersioned.value && JSON.stringify(currentState()) !== JSON.stringify(savedState.value)
|
||||
)
|
||||
const dirty = computed(() =>
|
||||
isVersioned.value ? versionList.value.some(draftChanged) : singleDirty.value
|
||||
)
|
||||
|
||||
function markSaved() {
|
||||
savedState.value = currentState()
|
||||
for (const d of versionList.value) if (draftChanged(d)) d.saved = draftCurrent(d)
|
||||
}
|
||||
|
||||
onBeforeRouteLeave(async () => {
|
||||
if (!dirty.value) return true
|
||||
return window.confirm(t('editor.leaveGuard'))
|
||||
})
|
||||
|
||||
/* preview ---------------------------------------------------------- */
|
||||
/* The textarea's seed stays partly in code: the LaTeX snippet cannot live
|
||||
verbatim in a message catalog (`{` would read as a parameter), so only the
|
||||
words are translated and the maths rides along here. */
|
||||
const SEED_MATH = '$$ \\zeta(s) = \\sum_{n=1}^{\\infty} \\frac{1}{n^s} $$'
|
||||
const contentPlaceholder = computed(
|
||||
() => `# ${t('editor.seedHeading')}\n\n${t('editor.seedTerms')}\n\n${SEED_MATH}`
|
||||
)
|
||||
|
||||
type Mode = 'write' | 'split' | 'preview'
|
||||
const mode = ref<Mode>('split')
|
||||
const previewContent = computed(() => content.value)
|
||||
|
||||
/* fullscreen -------------------------------------------------------- */
|
||||
const fullscreen = ref(false)
|
||||
const editorBodyEl = ref<HTMLElement | null>(null)
|
||||
let fullscreenAnim: Animation | null = null
|
||||
|
||||
/* FLIP the toggle: measure where the editor currently sits, flip the
|
||||
class (static box -> fixed full-screen box), then animate the old
|
||||
rect into the new one so the editor grows into the screen edges —
|
||||
or shrinks back to its place — instead of snapping. */
|
||||
async function toggleFullscreen() {
|
||||
const el = editorBodyEl.value
|
||||
if (!el) return
|
||||
|
||||
const first = el.getBoundingClientRect() // current visual rect, even mid-animation
|
||||
fullscreenAnim?.cancel()
|
||||
|
||||
fullscreen.value = !fullscreen.value
|
||||
await nextTick()
|
||||
|
||||
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) return
|
||||
const last = el.getBoundingClientRect()
|
||||
|
||||
const entering = fullscreen.value
|
||||
fullscreenAnim = el.animate(
|
||||
[
|
||||
{
|
||||
transformOrigin: 'top left',
|
||||
transform: `translate(${first.left - last.left}px, ${first.top - last.top}px) scale(${first.width / last.width}, ${first.height / last.height})`,
|
||||
borderRadius: entering ? '15px' : '0px',
|
||||
},
|
||||
{ transformOrigin: 'top left', transform: 'none', borderRadius: entering ? '0px' : '15px' },
|
||||
],
|
||||
{ duration: 300, easing: 'cubic-bezier(0.32, 0.72, 0, 1)' }
|
||||
)
|
||||
fullscreenAnim.onfinish = () => {
|
||||
fullscreenAnim = null
|
||||
}
|
||||
}
|
||||
|
||||
/* cheatsheet --------------------------------------------------------- */
|
||||
/* Popups don't stack in this app: SearchModal and SettingsModal hide
|
||||
each other on open. Search, settings and the profile can also be
|
||||
opened from anywhere (header, shortcuts) while the editor shows, so
|
||||
the cheatsheet steps aside whenever one of them opens. */
|
||||
const { open: searchOpen } = useSearch()
|
||||
const { open: settingsOpen } = useSettings()
|
||||
const { open: profileOpen } = useProfileMenu()
|
||||
|
||||
const cheatsheet = ref(false)
|
||||
|
||||
watch([searchOpen, settingsOpen, profileOpen], ([search, settings, profile]) => {
|
||||
if (search || settings || profile) cheatsheet.value = false
|
||||
})
|
||||
|
||||
// keep the page behind from scrolling while the editor fills the screen
|
||||
watch(fullscreen, (on) => {
|
||||
document.body.style.overflow = on ? 'hidden' : ''
|
||||
})
|
||||
onBeforeUnmount(() => {
|
||||
document.body.style.overflow = ''
|
||||
})
|
||||
|
||||
/* submit ----------------------------------------------------------- */
|
||||
const saving = ref(false)
|
||||
const errorMsg = ref('')
|
||||
|
||||
function parseTags(text: string): string[] {
|
||||
return text
|
||||
.split(',')
|
||||
.map((t) => t.trim().toLowerCase())
|
||||
.filter(Boolean)
|
||||
}
|
||||
|
||||
async function request(body: Record<string, unknown>, method: 'POST' | 'PUT', url: string) {
|
||||
return $fetch<ArticleMeta>(url, { method, body, headers: authHeaders() })
|
||||
}
|
||||
|
||||
async function save() {
|
||||
errorMsg.value = ''
|
||||
if (saving.value) return
|
||||
saving.value = true
|
||||
try {
|
||||
if (isVersioned.value) {
|
||||
/* every language version edited since the last save goes up together;
|
||||
brand-new ones join the article through its identity */
|
||||
const pendingDrafts = versionList.value.filter(draftChanged)
|
||||
if (!pendingDrafts.length) {
|
||||
await router.push(slugPreview.value)
|
||||
return
|
||||
}
|
||||
const missing = pendingDrafts.find((d) => !draftCurrent(d).title.trim())
|
||||
if (missing) {
|
||||
errorMsg.value = t('editor.versionNeedsTitle', { name: languageName(missing.language) })
|
||||
void switchLang(missing.language)
|
||||
return
|
||||
}
|
||||
let savedActive: ArticleMeta | null = null
|
||||
let lastSaved: ArticleMeta | null = null
|
||||
for (const d of pendingDrafts) {
|
||||
const cur = draftCurrent(d)
|
||||
const body = {
|
||||
title: cur.title.trim(),
|
||||
content: cur.content,
|
||||
tags: parseTags(cur.tagsText),
|
||||
/* a version written here joins the article it belongs to */
|
||||
...(d.slug ? {} : { baseSlug: identity, language: d.language }),
|
||||
}
|
||||
const saved = d.slug
|
||||
? await request(body, 'PUT', `${api}/articles/slug/${encodeURIComponent(d.slug)}`)
|
||||
: await request(body, 'POST', `${api}/articles`)
|
||||
d.slug = saved.slug
|
||||
d.saved = cur
|
||||
lastSaved = saved
|
||||
if (d.language === activeLang.value) savedActive = saved
|
||||
}
|
||||
/* leave on the page that was in view — the answer itself carries where
|
||||
it lives now, so a canonical retitle follows it instead of stranding */
|
||||
const target = savedActive ?? lastSaved
|
||||
await router.push(target ? versionHref(identityOf(target), target) : '/')
|
||||
return
|
||||
}
|
||||
|
||||
if (!title.value.trim()) {
|
||||
errorMsg.value = t('editor.titleRequired')
|
||||
return
|
||||
}
|
||||
const body = {
|
||||
title: title.value.trim(),
|
||||
content: content.value,
|
||||
language: language.value,
|
||||
/* a translation joins the article it translates rather than standing alone */
|
||||
...(original ? { baseSlug } : {}),
|
||||
tags: parseTags(tagsText.value),
|
||||
}
|
||||
const url =
|
||||
props.mode === 'create'
|
||||
? `${api}/articles`
|
||||
: `${api}/articles/slug/${encodeURIComponent(savedSlug)}`
|
||||
const saved = await request(body, props.mode === 'create' ? 'POST' : 'PUT', url)
|
||||
// prevent the leave-guard from firing on our own navigation
|
||||
markSaved()
|
||||
await router.push(versionHref(identityOf(saved), saved))
|
||||
} catch (err: any) {
|
||||
/* A session the API won't take any more. Signing out here would unmount this
|
||||
very form — and the draft in it — so instead the sign-in popup opens over
|
||||
the editor: whatever is written stays put, and signing back in replaces the
|
||||
dead token so the next save goes through. */
|
||||
if (err?.status === 401 || err?.statusCode === 401) {
|
||||
errorMsg.value = ''
|
||||
openSignIn({
|
||||
notice: err?.data?.message || t('editor.sessionExpired'),
|
||||
})
|
||||
return
|
||||
}
|
||||
errorMsg.value = err?.data?.message || t('editor.saveFailed')
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/* discard ---------------------------------------------------------- */
|
||||
/* The destructive step lives behind the same kind of popup as settings and
|
||||
the cheatsheet, not a browser alert. */
|
||||
const discardOpen = ref(false)
|
||||
const discardButtonEl = ref<HTMLButtonElement | null>(null)
|
||||
|
||||
const discardMessage = computed(() =>
|
||||
props.mode === 'create'
|
||||
? t('editor.discardNew')
|
||||
: dirtyCount.value > 1
|
||||
? t('editor.discardVersions', { n: dirtyCount.value })
|
||||
: t('editor.discardOne', {
|
||||
title: activeDraft()?.saved.title || savedState.value.title || t('editor.thisArticle'),
|
||||
})
|
||||
)
|
||||
|
||||
function askDiscard() {
|
||||
cheatsheet.value = false // popups don't stack in this app
|
||||
discardOpen.value = true
|
||||
}
|
||||
|
||||
function closeDiscardPrompt() {
|
||||
discardOpen.value = false
|
||||
discardButtonEl.value?.focus() // the popup it replaces was removed from the page
|
||||
}
|
||||
|
||||
/* Throw away everything typed since the last save and leave the editor — in
|
||||
every version, and versions added since the last save come off entirely.
|
||||
The baseline is what the form opened with, restoring which keeps our own
|
||||
leave-guard quiet; the way out leads back to the article or the search page. */
|
||||
async function discard() {
|
||||
discardOpen.value = false
|
||||
if (isVersioned.value) {
|
||||
for (const [lang, d] of Object.entries(drafts.value)) {
|
||||
if (!d.slug) delete drafts.value[lang] // a version never saved: gone whole
|
||||
else putDraftFieldsBack(d) // the rest return to their saved text
|
||||
}
|
||||
const back = activeDraft() ?? props.article
|
||||
if (activeDraft()) putDraftFields(activeDraft()) // the fields follow the version in view
|
||||
errorMsg.value = ''
|
||||
const target = back
|
||||
? versionHref(identity, { language: back.language ?? 'en', slug: back.slug })
|
||||
: '/'
|
||||
await router.push(target)
|
||||
return
|
||||
}
|
||||
const base = savedState.value
|
||||
title.value = base.title
|
||||
tagsText.value = base.tagsText
|
||||
content.value = base.content
|
||||
errorMsg.value = ''
|
||||
await router.push(
|
||||
props.mode === 'create' ? (original ? versionHref(baseSlug, original) : '/') : `/wiki/${savedSlug}`
|
||||
)
|
||||
}
|
||||
|
||||
function putDraftFieldsBack(d: VersionDraft) {
|
||||
// reset a draft's working copy to its saved text (the fields follow if active)
|
||||
d.title = d.saved.title
|
||||
d.tagsText = d.saved.tagsText
|
||||
d.content = d.saved.content
|
||||
}
|
||||
|
||||
/* Tab inserts spaces in the textarea ------------------------------- */
|
||||
function onTabKeydown(e: KeyboardEvent) {
|
||||
const el = e.target as HTMLTextAreaElement
|
||||
if (e.key !== 'Tab') return
|
||||
e.preventDefault()
|
||||
const { selectionStart: s, selectionEnd: end } = el
|
||||
content.value = content.value.slice(0, s) + ' ' + content.value.slice(end)
|
||||
nextTick(() => {
|
||||
el.selectionStart = el.selectionEnd = s + 2
|
||||
})
|
||||
}
|
||||
|
||||
// Ctrl/Cmd+S saves; Esc closes the topmost popup first, then leaves fullscreen
|
||||
function onGlobalKeydown(e: KeyboardEvent) {
|
||||
if (e.key === 'Escape') {
|
||||
if (addOpen.value) {
|
||||
addOpen.value = false
|
||||
return
|
||||
}
|
||||
if (discardOpen.value) {
|
||||
closeDiscardPrompt()
|
||||
return
|
||||
}
|
||||
if (cheatsheet.value) {
|
||||
cheatsheet.value = false
|
||||
return
|
||||
}
|
||||
if (fullscreen.value) {
|
||||
void toggleFullscreen()
|
||||
return
|
||||
}
|
||||
}
|
||||
if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 's') {
|
||||
e.preventDefault()
|
||||
if (!saving.value) save()
|
||||
}
|
||||
}
|
||||
onMounted(() => window.addEventListener('keydown', onGlobalKeydown))
|
||||
onBeforeUnmount(() => window.removeEventListener('keydown', onGlobalKeydown))
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<form class="editor-page" @submit.prevent="save">
|
||||
<div class="editor-head">
|
||||
<h1>{{ mode === 'create' ? (original ? t('editor.translateTitle') : t('editor.newTitle')) : t('editor.editTitle') }}</h1>
|
||||
<div class="editor-head-actions">
|
||||
<button
|
||||
ref="discardButtonEl"
|
||||
type="button"
|
||||
class="btn btn-ghost"
|
||||
:disabled="!dirty"
|
||||
:title="t('editor.discardHint')"
|
||||
@click="askDiscard"
|
||||
>
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
||||
<path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8" />
|
||||
<path d="M3 3v5h5" />
|
||||
</svg>
|
||||
{{ t('editor.discard') }}
|
||||
</button>
|
||||
<NuxtLink
|
||||
v-if="mode === 'edit' && savedSlug"
|
||||
:to="versionHref(identity, { language: article?.language, slug: savedSlug })"
|
||||
class="btn btn-ghost"
|
||||
>
|
||||
{{ t('common.cancel') }}
|
||||
</NuxtLink>
|
||||
<button class="btn btn-primary" type="submit" :disabled="saving">
|
||||
{{ saving
|
||||
? t('editor.saving')
|
||||
: original
|
||||
? t('editor.publishTranslation')
|
||||
: mode === 'create'
|
||||
? t('editor.publishArticle')
|
||||
: dirtyCount > 1
|
||||
? t('editor.saveVersions', { n: dirtyCount })
|
||||
: t('editor.saveChanges') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="original" class="translate-banner">
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
||||
<circle cx="12" cy="12" r="10" />
|
||||
<path d="M2 12h20" />
|
||||
<path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z" />
|
||||
</svg>
|
||||
<span>
|
||||
{{ t('editor.translating') }}
|
||||
<NuxtLink :to="versionHref(baseSlug, original)">{{ original.title }}</NuxtLink>
|
||||
{{ t('editor.translatingTail') }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<!-- the article's language versions: turn the editor to another language,
|
||||
or add one — unsaved text waits on its own version's page -->
|
||||
<div v-if="isVersioned" class="version-bar">
|
||||
<span class="version-bar-label">{{ t('editor.languages') }}</span>
|
||||
<button
|
||||
v-for="d in versionList"
|
||||
:key="d.language"
|
||||
type="button"
|
||||
class="lang-chip"
|
||||
:class="{ active: d.language === activeLang }"
|
||||
:lang="d.language"
|
||||
:aria-pressed="d.language === activeLang"
|
||||
:title="t('editor.editVersion', { name: languageName(d.language) })"
|
||||
@click="switchLang(d.language)"
|
||||
>
|
||||
{{ languageName(d.language) }}
|
||||
<span v-if="draftChanged(d)" class="dirty-dot" :title="t('editor.unsavedChanges')" />
|
||||
</button>
|
||||
<div v-if="freeLanguages.length" ref="addWrapEl" class="version-add">
|
||||
<button
|
||||
type="button"
|
||||
class="lang-chip version-add-btn"
|
||||
:aria-expanded="String(addOpen)"
|
||||
:title="t('editor.addLanguageHint')"
|
||||
@click="addOpen = !addOpen"
|
||||
>
|
||||
{{ t('editor.addLanguage') }}
|
||||
</button>
|
||||
<div v-if="addOpen" class="version-dropdown" role="listbox">
|
||||
<button
|
||||
v-for="l in freeLanguages"
|
||||
:key="l.code"
|
||||
type="button"
|
||||
class="topic-option"
|
||||
role="option"
|
||||
:lang="l.code"
|
||||
@click="addLanguage(l.code)"
|
||||
>
|
||||
<span>{{ l.name }}</span>
|
||||
<span class="topic-count">{{ l.code.toUpperCase() }}</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="article-title">{{ t('editor.titleLabel') }}</label>
|
||||
<input
|
||||
id="article-title"
|
||||
v-model="title"
|
||||
type="text"
|
||||
class="title-input"
|
||||
:placeholder="t('editor.titlePlaceholder')"
|
||||
autofocus
|
||||
/>
|
||||
<div v-if="title.trim()" class="slug-preview">
|
||||
{{ t('editor.urlLabel') }} <code>{{ slugPreview }}</code>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="field-row">
|
||||
<div class="field">
|
||||
<label for="article-tags">
|
||||
{{ t('editor.tagsLabel') }} <span class="hint">{{ t('editor.tagsHint') }}</span>
|
||||
</label>
|
||||
<input id="article-tags" v-model="tagsText" type="text" :placeholder="t('editor.tagsPlaceholder')" />
|
||||
</div>
|
||||
|
||||
<div v-if="!isVersioned" class="field">
|
||||
<label for="article-language">
|
||||
{{ t('editor.languageLabel') }} <span class="hint">{{ t('editor.languageHint') }}</span>
|
||||
</label>
|
||||
<select id="article-language" v-model="language">
|
||||
<option
|
||||
v-for="l in languages"
|
||||
:key="l.code"
|
||||
:value="l.code"
|
||||
:lang="l.code"
|
||||
:disabled="l.taken"
|
||||
:title="l.taken ? t('editor.languageTaken') : undefined"
|
||||
>
|
||||
{{ l.name }}{{ l.taken ? ` ${t('editor.alreadyWritten')}` : '' }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="article-content" :lang="isVersioned ? activeLang : undefined">
|
||||
{{ t('editor.contentLabel') }} <span class="hint">{{ t('editor.contentHint') }}</span>
|
||||
</label>
|
||||
<div ref="editorBodyEl" class="editor-body" :class="{ 'is-fullscreen': fullscreen }">
|
||||
<div class="editor-toolbar">
|
||||
<button type="button" class="mode-btn" :class="{ active: mode === 'write' }" @click="mode = 'write'">{{ t('editor.modeWrite') }}</button>
|
||||
<button type="button" class="mode-btn" :class="{ active: mode === 'split' }" @click="mode = 'split'">{{ t('editor.modeSplit') }}</button>
|
||||
<button type="button" class="mode-btn" :class="{ active: mode === 'preview' }" @click="mode = 'preview'">{{ t('editor.modePreview') }}</button>
|
||||
<div class="toolbar-actions">
|
||||
<button
|
||||
type="button"
|
||||
class="mode-btn toolbar-icon-btn"
|
||||
:class="{ active: cheatsheet }"
|
||||
:title="t('editor.cheatsheetHint')"
|
||||
:aria-label="t('editor.cheatsheet')"
|
||||
:aria-pressed="cheatsheet"
|
||||
@click="cheatsheet = !cheatsheet"
|
||||
>
|
||||
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
||||
<circle cx="12" cy="12" r="10" />
|
||||
<path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3" />
|
||||
<path d="M12 17h.01" />
|
||||
</svg>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="mode-btn toolbar-icon-btn"
|
||||
:title="fullscreen ? t('editor.exitFullscreenHint') : t('editor.fullscreen')"
|
||||
:aria-label="fullscreen ? t('editor.exitFullscreen') : t('editor.enterFullscreen')"
|
||||
:aria-pressed="fullscreen"
|
||||
@click="toggleFullscreen"
|
||||
>
|
||||
<svg v-if="!fullscreen" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
||||
<path d="M8 3H5a2 2 0 0 0-2 2v3" />
|
||||
<path d="M21 8V5a2 2 0 0 0-2-2h-3" />
|
||||
<path d="M3 16v3a2 2 0 0 0 2 2h3" />
|
||||
<path d="M16 21h3a2 2 0 0 0 2-2v-3" />
|
||||
</svg>
|
||||
<svg v-else width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
||||
<path d="M8 3v3a2 2 0 0 1-2 2H3" />
|
||||
<path d="M21 8h-3a2 2 0 0 1-2-2V3" />
|
||||
<path d="M3 16h3a2 2 0 0 1 2 2v3" />
|
||||
<path d="M16 21v-3a2 2 0 0 1 2-2h3" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="editor-grid" :class="`mode-${mode}`">
|
||||
<div class="write-pane">
|
||||
<textarea
|
||||
id="article-content"
|
||||
v-model="content"
|
||||
class="md-input"
|
||||
:lang="isVersioned ? activeLang : undefined"
|
||||
:placeholder="contentPlaceholder"
|
||||
spellcheck="false"
|
||||
@keydown="onTabKeydown"
|
||||
/>
|
||||
</div>
|
||||
<div class="preview-pane">
|
||||
<div class="preview-label">{{ t('editor.livePreview') }}</div>
|
||||
<MarkdownView :content="previewContent || `*${t('editor.noPreview')}*`" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p v-if="errorMsg" class="form-error">{{ errorMsg }}</p>
|
||||
|
||||
<EditorCheatsheet :open="cheatsheet" @close="cheatsheet = false" />
|
||||
|
||||
<ConfirmModal
|
||||
:open="discardOpen"
|
||||
:title="t('editor.discardConfirm')"
|
||||
:message="discardMessage"
|
||||
:confirm-label="t('editor.discard')"
|
||||
:cancel-label="t('editor.keepEditing')"
|
||||
@confirm="discard"
|
||||
@cancel="closeDiscardPrompt"
|
||||
/>
|
||||
</form>
|
||||
</template>
|
||||
143
frontend/app/components/ArticleLanguageMenu.vue
Normal file
143
frontend/app/components/ArticleLanguageMenu.vue
Normal file
@@ -0,0 +1,143 @@
|
||||
<script setup lang="ts">
|
||||
/* The reader's language menu: one control for turning the article to another
|
||||
language — and for writing one it doesn't exist in yet. Every language the
|
||||
wiki keeps is listed: the ones this article speaks navigate to that
|
||||
version, the rest lead straight into the translate editor with the language
|
||||
already chosen. */
|
||||
import type { ArticleVersion } from './ArticleCard.vue'
|
||||
|
||||
const props = defineProps<{
|
||||
/** the article the versions belong to — its canonical slug */
|
||||
identity: string
|
||||
versions: ArticleVersion[]
|
||||
/** the version in view and the language it is written in */
|
||||
currentSlug: string
|
||||
language: string
|
||||
/** the slug the translate flow answers to: the canonical document's, or
|
||||
this version's own when the canonical one is gone */
|
||||
editorSlug: string
|
||||
}>()
|
||||
|
||||
const route = useRoute()
|
||||
const { t } = useI18n()
|
||||
const { open, hide } = useLanguageMenu()
|
||||
const { open: searchOpen } = useSearch()
|
||||
const { open: settingsOpen } = useSettings()
|
||||
const { open: profileOpen } = useProfileMenu()
|
||||
const { loggedIn } = useAuth()
|
||||
|
||||
/* the languages this article exists in, and the ones still left to write —
|
||||
writing takes an account, so a visitor who isn't signed in only ever sees
|
||||
the versions there are to read */
|
||||
const existing = computed(() => props.versions)
|
||||
const missing = computed(() =>
|
||||
loggedIn.value
|
||||
? LANGUAGES.filter((l) => !props.versions.some((v) => (v.language || 'en') === l.code))
|
||||
: []
|
||||
)
|
||||
|
||||
function toggle() {
|
||||
open.value = !open.value
|
||||
}
|
||||
|
||||
/* the menu is one of the app's popups: closed by a click outside, by esc, by
|
||||
navigating, and by search or settings opening over it */
|
||||
const wrapEl = ref<HTMLElement | null>(null)
|
||||
|
||||
function onDocClick(e: MouseEvent) {
|
||||
if (open.value && !wrapEl.value?.contains(e.target as Node)) hide()
|
||||
}
|
||||
function onKeydown(e: KeyboardEvent) {
|
||||
if (e.key === 'Escape' && open.value) hide()
|
||||
}
|
||||
onMounted(() => {
|
||||
document.addEventListener('click', onDocClick)
|
||||
window.addEventListener('keydown', onKeydown)
|
||||
})
|
||||
onBeforeUnmount(() => {
|
||||
document.removeEventListener('click', onDocClick)
|
||||
window.removeEventListener('keydown', onKeydown)
|
||||
})
|
||||
|
||||
watch(() => route.fullPath, hide)
|
||||
watch([searchOpen, settingsOpen, profileOpen], ([search, settings, profile]) => {
|
||||
if (search || settings || profile) hide()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div ref="wrapEl" class="lang-menu">
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-ghost btn-sm"
|
||||
:aria-expanded="String(open)"
|
||||
:title="loggedIn ? t('langMenu.hintSignedIn') : t('langMenu.hint')"
|
||||
@click="toggle"
|
||||
>
|
||||
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
||||
<circle cx="12" cy="12" r="10" />
|
||||
<path d="M2 12h20" />
|
||||
<path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z" />
|
||||
</svg>
|
||||
<span :lang="language">{{ languageName(language) }}</span>
|
||||
<svg class="lang-menu-caret" width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
||||
<path d="m6 9 6 6 6-6" />
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
<div v-if="open" class="lang-menu-dropdown" role="menu" :aria-label="t('langMenu.aria')">
|
||||
<template v-if="existing.length">
|
||||
<div class="lang-menu-section">{{ t('langMenu.readIn') }}</div>
|
||||
<NuxtLink
|
||||
v-for="v in existing"
|
||||
:key="v.slug"
|
||||
:to="versionHref(identity, v)"
|
||||
class="lang-menu-item"
|
||||
:lang="v.language"
|
||||
role="menuitem"
|
||||
:aria-current="v.slug === currentSlug ? 'true' : undefined"
|
||||
@click="hide"
|
||||
>
|
||||
<span class="lmi-name">{{ languageName(v.language) }}</span>
|
||||
<span class="lmi-sub">{{ v.title }}</span>
|
||||
<svg
|
||||
v-if="v.slug === currentSlug"
|
||||
class="lmi-check"
|
||||
width="13"
|
||||
height="13"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2.6"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<path d="M20 6 9 17l-5-5" />
|
||||
</svg>
|
||||
</NuxtLink>
|
||||
</template>
|
||||
|
||||
<template v-if="missing.length">
|
||||
<div class="lang-menu-section" :class="{ 'lang-menu-gap': existing.length }">
|
||||
{{ t('langMenu.writeIn') }}
|
||||
</div>
|
||||
<NuxtLink
|
||||
v-for="l in missing"
|
||||
:key="l.code"
|
||||
:to="{ path: '/new', query: { translate: editorSlug, lang: l.code } }"
|
||||
class="lang-menu-item lang-menu-write"
|
||||
:lang="l.code"
|
||||
role="menuitem"
|
||||
:title="t('langMenu.writeArticleIn', { name: l.name })"
|
||||
@click="hide"
|
||||
>
|
||||
<span class="lmi-name">{{ l.name }}</span>
|
||||
<svg class="lmi-pencil" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
||||
<path d="M12 20h9M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z" />
|
||||
</svg>
|
||||
</NuxtLink>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
146
frontend/app/components/ArticlePane.vue
Normal file
146
frontend/app/components/ArticlePane.vue
Normal file
@@ -0,0 +1,146 @@
|
||||
<script setup lang="ts">
|
||||
/* One page of the open book. Its left edge is a spine — the title, set
|
||||
vertically, with the × that closes the page — and the article itself
|
||||
scrolls on its own inside the page. A newer page slides over this one and
|
||||
leaves only the spine showing, the way a stack of read pages does; click
|
||||
anywhere on the page — or its spine — to turn back to it.
|
||||
|
||||
Everything but the spine of a page that isn't in view is `inert`: it can
|
||||
still be seen while you slide the stack sideways, but it doesn't take
|
||||
focus or clicks — the pane's own click handler catches those instead, so
|
||||
one click turns to the page before its links do anything. */
|
||||
const props = defineProps<{
|
||||
slug: string
|
||||
index: number
|
||||
active: boolean
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
activate: []
|
||||
close: []
|
||||
remove: []
|
||||
}>()
|
||||
|
||||
const { get, unreadable } = useArticleLibrary()
|
||||
const { t, locale } = useI18n()
|
||||
const { th } = useAppLocale()
|
||||
|
||||
const article = computed(() => get(props.slug))
|
||||
const failed = computed(() => props.slug in unreadable.value)
|
||||
const title = computed(() => article.value?.title ?? props.slug)
|
||||
const language = computed(() => articleLanguage(article.value ?? {}))
|
||||
const languageLabel = computed(() => languageName(language.value))
|
||||
/* every language this article exists in, the one in view included */
|
||||
const versions = computed(() => article.value?.versions ?? [])
|
||||
/* the article behind this document, and the slug its editor answers to:
|
||||
the identity when the canonical version is still around, this document's
|
||||
own slug when only translations of it remain */
|
||||
const identity = computed(() => identityOf(article.value ?? { slug: props.slug }))
|
||||
const editorSlug = computed(() =>
|
||||
versions.value.some((v) => v.slug === identity.value) ? identity.value : props.slug
|
||||
)
|
||||
|
||||
const updated = computed(() => {
|
||||
const d = article.value?.updatedAt ? new Date(article.value.updatedAt) : null
|
||||
if (!d || Number.isNaN(d.getTime())) return ''
|
||||
return d.toLocaleDateString(locale.value, { dateStyle: 'medium' })
|
||||
})
|
||||
|
||||
function turnToThisPage() {
|
||||
if (!props.active) emit('activate')
|
||||
}
|
||||
|
||||
/* a tag read at the foot of the article: “probability” → “Probability” */
|
||||
function topicLabel(tag: string) {
|
||||
const t = tag.trim()
|
||||
return t.charAt(0).toUpperCase() + t.slice(1)
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section
|
||||
class="book-pane"
|
||||
:class="{ active }"
|
||||
:data-slug="slug"
|
||||
:data-index="index"
|
||||
:style="{ '--i': index }"
|
||||
:aria-label="t('pane.aria', { title })"
|
||||
@click="turnToThisPage"
|
||||
>
|
||||
<div
|
||||
class="pane-spine"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
:aria-current="active ? 'page' : undefined"
|
||||
:aria-disabled="active"
|
||||
:title="t('pane.spineHint', { title })"
|
||||
@click.stop="turnToThisPage"
|
||||
@keydown.enter.prevent="turnToThisPage"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="spine-close"
|
||||
:aria-label="t('common.closeTab')"
|
||||
@click.stop="emit('close')"
|
||||
>
|
||||
<svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.6" stroke-linecap="round" aria-hidden="true">
|
||||
<path d="M6 6l12 12M18 6L6 18" />
|
||||
</svg>
|
||||
</button>
|
||||
<span class="spine-title">{{ title }}</span>
|
||||
</div>
|
||||
|
||||
<div class="pane-body" :inert="active ? null : ''">
|
||||
<div class="pane-scroll">
|
||||
<div v-if="failed && !article" class="empty">
|
||||
<div class="glyph">!</div>
|
||||
<h3>{{ t('pane.readFailTitle') }}</h3>
|
||||
<p v-html="th('pane.readFailText', { path: `/wiki/${slug}` })"></p>
|
||||
</div>
|
||||
|
||||
<div v-else-if="!article" class="pane-skeleton">
|
||||
<div class="skeleton" style="height: 36px; width: 52%; margin-bottom: 14px" />
|
||||
<div class="skeleton" style="height: 18px; width: 78%; margin-bottom: 36px; border-radius: 8px" />
|
||||
<div class="skeleton" style="height: 220px" />
|
||||
</div>
|
||||
|
||||
<article v-else class="article-page">
|
||||
<header class="article-head">
|
||||
<div class="article-eyebrow">
|
||||
<span v-if="updated">{{ t('pane.lastEdited', { date: updated }) }}</span>
|
||||
</div>
|
||||
<div class="article-title-row">
|
||||
<h1 class="article-title" :lang="language">{{ article.title }}</h1>
|
||||
<div v-if="active" class="article-actions">
|
||||
<ArticleActionsMenu
|
||||
:identity="identity"
|
||||
:versions="versions"
|
||||
:current-slug="slug"
|
||||
:language="language"
|
||||
:editor-slug="editorSlug"
|
||||
@remove="emit('remove')"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="article-body">
|
||||
<MarkdownView :content="article.content ?? ''" :namespace="slug" intercept-links />
|
||||
</div>
|
||||
|
||||
<footer v-if="article.tags?.length" class="article-topics">
|
||||
<span class="article-topics-label">{{ t('pane.topicsLabel') }}</span>
|
||||
<NuxtLink
|
||||
v-for="t in article.tags"
|
||||
:key="t"
|
||||
:to="{ path: '/articles/', query: { tag: t } }"
|
||||
class="topic-link"
|
||||
>
|
||||
{{ topicLabel(t) }}
|
||||
</NuxtLink>
|
||||
</footer>
|
||||
</article>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
44
frontend/app/components/AuthGate.vue
Normal file
44
frontend/app/components/AuthGate.vue
Normal file
@@ -0,0 +1,44 @@
|
||||
<script setup lang="ts">
|
||||
/* Reading Mathew is open to everyone; writing it takes an account. The editor
|
||||
pages wrap their form in this, so a visitor who follows “New article” without
|
||||
one lands somewhere that says what is missing and offers the way in, instead
|
||||
of a form that quietly refuses to save. Nothing is fetched or mounted behind
|
||||
the gate until there is a session. */
|
||||
const { loggedIn } = useAuth()
|
||||
const { show } = useSignInPopup()
|
||||
const { t } = useI18n()
|
||||
|
||||
const props = defineProps<{
|
||||
heading?: string
|
||||
text?: string
|
||||
}>()
|
||||
|
||||
/* the defaults live here rather than in withDefaults so they follow the
|
||||
interface language as it changes */
|
||||
const headingText = computed(() => props.heading ?? t('gate.heading'))
|
||||
const textText = computed(() => props.text ?? t('gate.text'))
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<slot v-if="loggedIn" />
|
||||
|
||||
<section v-else class="auth-gate" aria-labelledby="auth-gate-heading">
|
||||
<span class="auth-gate-mark" aria-hidden="true">
|
||||
<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round">
|
||||
<circle cx="8" cy="15" r="4" />
|
||||
<path d="m10.8 12.2 8.2-8.2 2 2-2 2 1.5 1.5-2 2-1.5-1.5-1.7 1.7" />
|
||||
</svg>
|
||||
</span>
|
||||
<h1 id="auth-gate-heading" class="auth-gate-title">{{ headingText }}</h1>
|
||||
<p class="auth-gate-text">{{ textText }}</p>
|
||||
<div class="auth-gate-actions">
|
||||
<button type="button" class="btn btn-primary" @click="show({ mode: 'signin' })">
|
||||
{{ t('auth.signin') }}
|
||||
</button>
|
||||
<button type="button" class="btn btn-ghost" @click="show({ mode: 'signup' })">
|
||||
{{ t('auth.signup') }}
|
||||
</button>
|
||||
</div>
|
||||
<p class="auth-gate-fine">{{ t('gate.fine') }}</p>
|
||||
</section>
|
||||
</template>
|
||||
194
frontend/app/components/AuthModal.vue
Normal file
194
frontend/app/components/AuthModal.vue
Normal file
@@ -0,0 +1,194 @@
|
||||
<script setup lang="ts">
|
||||
/* Both ways in — into an existing account or a new one — in a single popup,
|
||||
drawn and closed in the same shape as the settings popup: esc, the backdrop,
|
||||
the ✕, or moving to another page. Whoever opens it chooses a tab and may leave
|
||||
a line of explanation above the form (see useSignInPopup); the editor uses
|
||||
that when a save comes back saying the session has gone.
|
||||
|
||||
Signing in is enough on its own: the editor pages show their form as soon as
|
||||
there is a session, so the page behind this popup is already ready when it
|
||||
closes — whatever was being written is still there. */
|
||||
const { open, mode, notice, show, hide } = useSignInPopup()
|
||||
const { hide: hideSearch } = useSearch()
|
||||
const { hide: hideSettings } = useSettings()
|
||||
const { hide: hideProfile } = useProfileMenu()
|
||||
const { signIn, signUp } = useAuth()
|
||||
const { applyAccount } = useAppLocale()
|
||||
const { t } = useI18n()
|
||||
const route = useRoute()
|
||||
|
||||
const username = ref('')
|
||||
const password = ref('')
|
||||
const errorMsg = ref('')
|
||||
const busy = ref(false)
|
||||
const panelEl = ref<HTMLElement | null>(null)
|
||||
const usernameEl = ref<HTMLInputElement | null>(null)
|
||||
|
||||
const isSignUp = computed(() => mode.value === 'signup')
|
||||
const heading = computed(() => (isSignUp.value ? t('auth.signup') : t('auth.signin')))
|
||||
const submitLabel = computed(() =>
|
||||
busy.value ? t('auth.busy') : isSignUp.value ? t('auth.signupSubmit') : t('auth.signin')
|
||||
)
|
||||
|
||||
watch(
|
||||
open,
|
||||
async (isOpen) => {
|
||||
if (!isOpen) return
|
||||
// opening this shouldn't leave another popup stacked behind it
|
||||
hideSearch()
|
||||
hideSettings()
|
||||
hideProfile()
|
||||
errorMsg.value = ''
|
||||
await nextTick()
|
||||
usernameEl.value?.focus()
|
||||
},
|
||||
{ flush: 'post' }
|
||||
)
|
||||
|
||||
/* Switching tabs keeps the username — the same person either way — but not the
|
||||
password, which is a different secret in each direction. */
|
||||
function setMode(next: SignInMode) {
|
||||
if (mode.value === next) return
|
||||
show({ mode: next })
|
||||
password.value = ''
|
||||
errorMsg.value = ''
|
||||
}
|
||||
|
||||
async function submit() {
|
||||
if (busy.value) return
|
||||
errorMsg.value = ''
|
||||
busy.value = true
|
||||
try {
|
||||
// the account decides the interface language — let it overrule the device
|
||||
const user = isSignUp.value ? await signUp(username.value, password.value) : await signIn(username.value, password.value)
|
||||
applyAccount(user?.locale)
|
||||
password.value = ''
|
||||
hide()
|
||||
} catch (err: any) {
|
||||
errorMsg.value = err?.data?.message || t('common.apiUnreachable')
|
||||
} finally {
|
||||
busy.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/* --- esc closes, navigation closes --- */
|
||||
function onGlobalKeydown(e: KeyboardEvent) {
|
||||
if (e.key === 'Escape' && open.value) hide()
|
||||
}
|
||||
onMounted(() => window.addEventListener('keydown', onGlobalKeydown))
|
||||
onBeforeUnmount(() => window.removeEventListener('keydown', onGlobalKeydown))
|
||||
|
||||
watch(
|
||||
() => route.fullPath,
|
||||
() => {
|
||||
if (open.value) hide()
|
||||
}
|
||||
)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Teleport to="body">
|
||||
<Transition name="auth-popup">
|
||||
<div v-if="open" class="auth-overlay" @click.self="hide()">
|
||||
<div
|
||||
ref="panelEl"
|
||||
class="auth-modal"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
:aria-label="heading"
|
||||
tabindex="-1"
|
||||
>
|
||||
<div class="auth-modal-head">
|
||||
<h2 class="auth-title">{{ heading }}</h2>
|
||||
<button
|
||||
type="button"
|
||||
class="panel-icon-btn"
|
||||
:aria-label="t('common.close')"
|
||||
:title="t('common.close')"
|
||||
@click="hide()"
|
||||
>
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round">
|
||||
<path d="M6 6l12 12M18 6L6 18" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="auth-modal-body">
|
||||
<div class="auth-tabs" role="tablist" :aria-label="t('auth.tabsAria')">
|
||||
<button
|
||||
type="button"
|
||||
role="tab"
|
||||
class="auth-tab"
|
||||
:class="{ active: !isSignUp }"
|
||||
:aria-selected="!isSignUp"
|
||||
@click="setMode('signin')"
|
||||
>
|
||||
{{ t('auth.signin') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
role="tab"
|
||||
class="auth-tab"
|
||||
:class="{ active: isSignUp }"
|
||||
:aria-selected="isSignUp"
|
||||
@click="setMode('signup')"
|
||||
>
|
||||
{{ t('auth.signupTab') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<p v-if="notice" class="auth-notice">{{ notice }}</p>
|
||||
|
||||
<form @submit.prevent="submit">
|
||||
<div class="field">
|
||||
<label for="auth-username">{{ t('auth.username') }}</label>
|
||||
<input
|
||||
id="auth-username"
|
||||
ref="usernameEl"
|
||||
v-model="username"
|
||||
type="text"
|
||||
autocomplete="username"
|
||||
autocapitalize="none"
|
||||
spellcheck="false"
|
||||
:placeholder="t('auth.usernamePlaceholder')"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="auth-password">
|
||||
{{ t('auth.password') }} <span class="hint">{{ t('auth.passwordHint') }}</span>
|
||||
</label>
|
||||
<input
|
||||
id="auth-password"
|
||||
v-model="password"
|
||||
type="password"
|
||||
:autocomplete="isSignUp ? 'new-password' : 'current-password'"
|
||||
minlength="8"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
<p v-if="errorMsg" class="form-error">{{ errorMsg }}</p>
|
||||
|
||||
<button type="submit" class="btn btn-primary auth-submit" :disabled="busy">
|
||||
{{ submitLabel }}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<p class="auth-switch">
|
||||
<template v-if="isSignUp">
|
||||
{{ t('auth.haveAccount') }}
|
||||
<button type="button" @click="setMode('signin')">{{ t('auth.signin') }}</button>
|
||||
</template>
|
||||
<template v-else>
|
||||
{{ t('auth.newToMathew') }}
|
||||
<button type="button" @click="setMode('signup')">{{ t('auth.signup') }}</button>
|
||||
</template>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Transition>
|
||||
</Teleport>
|
||||
</template>
|
||||
62
frontend/app/components/ConfirmModal.vue
Normal file
62
frontend/app/components/ConfirmModal.vue
Normal file
@@ -0,0 +1,62 @@
|
||||
<script setup lang="ts">
|
||||
/* Yes/no popup, same shape as the settings and cheatsheet modals: teleported
|
||||
overlay, dismissed by the backdrop or the safe button. Esc is left to the
|
||||
caller, which is how the editor already orders its own popups. */
|
||||
const props = defineProps<{
|
||||
open: boolean
|
||||
title?: string
|
||||
message?: string
|
||||
confirmLabel?: string
|
||||
cancelLabel?: string
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
/* the defaults live here rather than in withDefaults so they follow the
|
||||
interface language as it changes */
|
||||
const titleText = computed(() => props.title ?? t('common.areYouSure'))
|
||||
const confirmText = computed(() => props.confirmLabel ?? t('common.confirm'))
|
||||
const cancelText = computed(() => props.cancelLabel ?? t('common.cancel'))
|
||||
|
||||
const emit = defineEmits<{ confirm: []; cancel: [] }>()
|
||||
|
||||
const cancelButtonEl = ref<HTMLButtonElement | null>(null)
|
||||
|
||||
/* land on the safe button when the popup opens, so Enter can never trigger
|
||||
the destructive action by accident */
|
||||
watch(
|
||||
() => props.open,
|
||||
async (isOpen) => {
|
||||
if (!isOpen) return
|
||||
await nextTick()
|
||||
cancelButtonEl.value?.focus()
|
||||
},
|
||||
{ flush: 'post' }
|
||||
)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Teleport to="body">
|
||||
<Transition name="confirm-popup">
|
||||
<div v-if="open" class="confirm-overlay" @click.self="emit('cancel')">
|
||||
<div class="confirm-modal" role="dialog" aria-modal="true" :aria-label="titleText">
|
||||
<h2 class="confirm-title">{{ titleText }}</h2>
|
||||
<p v-if="message" class="confirm-message">{{ message }}</p>
|
||||
<div class="confirm-actions">
|
||||
<button
|
||||
ref="cancelButtonEl"
|
||||
type="button"
|
||||
class="btn btn-ghost"
|
||||
@click="emit('cancel')"
|
||||
>
|
||||
{{ cancelText }}
|
||||
</button>
|
||||
<button type="button" class="btn btn-danger" @click="emit('confirm')">
|
||||
{{ confirmText }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Transition>
|
||||
</Teleport>
|
||||
</template>
|
||||
145
frontend/app/components/EditorCheatsheet.vue
Normal file
145
frontend/app/components/EditorCheatsheet.vue
Normal file
@@ -0,0 +1,145 @@
|
||||
<script setup lang="ts">
|
||||
/* Writing-help popup for the editor, opened by the "?" in the toolbar.
|
||||
Same shape as SettingsModal: teleported overlay, closes on backdrop
|
||||
click or the × (Esc is handled by ArticleForm, which also keeps it in
|
||||
front of the fullscreen toggle). */
|
||||
defineProps<{ open: boolean }>()
|
||||
const emit = defineEmits<{ close: [] }>()
|
||||
const { t } = useI18n()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Teleport to="body">
|
||||
<Transition name="cheatsheet-popup">
|
||||
<div v-if="open" class="cheatsheet-overlay" @click.self="emit('close')">
|
||||
<div
|
||||
class="cheatsheet-modal"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
:aria-label="t('cheatsheet.title')"
|
||||
>
|
||||
<div class="cheatsheet-head">
|
||||
<h2 class="cheatsheet-title">{{ t('cheatsheet.title') }}</h2>
|
||||
<button
|
||||
type="button"
|
||||
class="panel-icon-btn"
|
||||
:aria-label="t('cheatsheet.closeAria')"
|
||||
:title="t('common.close')"
|
||||
@click="emit('close')"
|
||||
>
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round">
|
||||
<path d="M6 6l12 12M18 6L6 18" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="cheatsheet-body">
|
||||
<section class="cheatsheet-group">
|
||||
<h3 class="cheatsheet-group-title">{{ t('cheatsheet.links') }}</h3>
|
||||
<div class="cheat-row">
|
||||
<code>[[Riemann zeta function]]</code>
|
||||
<span>{{ t('cheatsheet.linkByTitle') }}</span>
|
||||
</div>
|
||||
<div class="cheat-row">
|
||||
<code>[[Cauchy–Schwarz|the inequality]]</code>
|
||||
<span>{{ t('cheatsheet.linkOwnWording') }}</span>
|
||||
</div>
|
||||
<div class="cheat-row">
|
||||
<code>[text](https://example.org)</code>
|
||||
<span>{{ t('cheatsheet.linkWebPage') }}</span>
|
||||
</div>
|
||||
<div class="cheat-row">
|
||||
<code>https://example.org</code>
|
||||
<span>{{ t('cheatsheet.bareUrl') }}</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="cheatsheet-group">
|
||||
<h3 class="cheatsheet-group-title">{{ t('cheatsheet.math') }}</h3>
|
||||
<div class="cheat-row">
|
||||
<code>$e^{i\pi}+1=0$</code>
|
||||
<span>{{ t('cheatsheet.inline') }} — <KatexSpan tex="\,e^{i\pi}+1=0\," /></span>
|
||||
</div>
|
||||
<div class="cheat-row">
|
||||
<code>$$\frac{\pi^2}{6}$$</code>
|
||||
<span>{{ t('cheatsheet.display') }} — <KatexSpan tex="\,\tfrac{\pi^2}{6}\," /></span>
|
||||
</div>
|
||||
<div class="cheat-row">
|
||||
<code>\R \N \Z \Q \C</code>
|
||||
<span>{{ t('cheatsheet.numberSets') }} — <KatexSpan tex="\,\R\ \N\ \Z\ \Q\ \C\," /></span>
|
||||
</div>
|
||||
<div class="cheat-row">
|
||||
<code>\sum \int \frac{a}{b} \sqrt{x}</code>
|
||||
<span>{{ t('cheatsheet.sumsEtc') }}</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="cheatsheet-group">
|
||||
<h3 class="cheatsheet-group-title">{{ t('cheatsheet.text') }}</h3>
|
||||
<div class="cheat-row">
|
||||
<code>**bold** *italic*</code>
|
||||
<span v-html="t('cheatsheet.boldItalic')"></span>
|
||||
</div>
|
||||
<div class="cheat-row">
|
||||
<code>~~struck out~~</code>
|
||||
<span v-html="t('cheatsheet.struckOut')"></span>
|
||||
</div>
|
||||
<div class="cheat-row">
|
||||
<code>`inline code`</code>
|
||||
<span>{{ t('cheatsheet.shadedCode') }}</span>
|
||||
</div>
|
||||
<div class="cheat-row">
|
||||
<code>```python … ```</code>
|
||||
<span>{{ t('cheatsheet.fencedBlock') }}</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="cheatsheet-group">
|
||||
<h3 class="cheatsheet-group-title">{{ t('cheatsheet.blocks') }}</h3>
|
||||
<div class="cheat-row">
|
||||
<code># ## ###</code>
|
||||
<span>{{ t('cheatsheet.headings') }}</span>
|
||||
</div>
|
||||
<div class="cheat-row">
|
||||
<code>- item</code>
|
||||
<span>{{ t('cheatsheet.bulletList') }}</span>
|
||||
</div>
|
||||
<div class="cheat-row">
|
||||
<code>1. item</code>
|
||||
<span>{{ t('cheatsheet.numberedList') }}</span>
|
||||
</div>
|
||||
<div class="cheat-row">
|
||||
<code>> quote</code>
|
||||
<span>{{ t('cheatsheet.blockquote') }}</span>
|
||||
</div>
|
||||
<div class="cheat-row">
|
||||
<code>| a | b |</code>
|
||||
<span>{{ t('cheatsheet.tableRows') }}</span>
|
||||
</div>
|
||||
<div class="cheat-row">
|
||||
<code>---</code>
|
||||
<span>{{ t('cheatsheet.hr') }}</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="cheatsheet-group">
|
||||
<h3 class="cheatsheet-group-title">{{ t('cheatsheet.shortcuts') }}</h3>
|
||||
<div class="cheat-row">
|
||||
<code>Ctrl / ⌘ + S</code>
|
||||
<span>{{ t('cheatsheet.saveShortcut') }}</span>
|
||||
</div>
|
||||
<div class="cheat-row">
|
||||
<code>Tab</code>
|
||||
<span>{{ t('cheatsheet.tabIndent') }}</span>
|
||||
</div>
|
||||
<div class="cheat-row">
|
||||
<code>Esc</code>
|
||||
<span>{{ t('cheatsheet.escHelp') }}</span>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Transition>
|
||||
</Teleport>
|
||||
</template>
|
||||
574
frontend/app/components/GraphView.vue
Normal file
574
frontend/app/components/GraphView.vue
Normal file
@@ -0,0 +1,574 @@
|
||||
<script setup lang="ts">
|
||||
/* The link map, Obsidian-style: every article is a node, every link from
|
||||
one article's text into another is an edge between them. A small
|
||||
hand-rolled force simulation (pairwise repulsion, springs along the
|
||||
edges, a gentle pull to the centre) settles the nodes into a shape,
|
||||
and everything is painted on one canvas: drag the background to pan,
|
||||
the wheel to zoom, a node to pull it around, and let go of a node
|
||||
where it was pressed to open that article. */
|
||||
|
||||
export interface GraphNodeDto {
|
||||
slug: string
|
||||
title: string
|
||||
tags?: string[]
|
||||
links: number
|
||||
}
|
||||
|
||||
export interface GraphEdgeDto {
|
||||
source: string
|
||||
target: string
|
||||
}
|
||||
|
||||
const props = defineProps<{ nodes: GraphNodeDto[]; edges: GraphEdgeDto[] }>()
|
||||
|
||||
const router = useRouter()
|
||||
const wrapEl = ref<HTMLElement | null>(null)
|
||||
const canvasEl = ref<HTMLCanvasElement | null>(null)
|
||||
const cursor = ref<'grab' | 'grabbing' | 'pointer'>('grab')
|
||||
const hoverTitle = ref('')
|
||||
const { t } = useI18n()
|
||||
|
||||
/* the simulation is plain mutable state — it ticks every frame, and
|
||||
Vue would only slow it down */
|
||||
interface SimNode {
|
||||
slug: string
|
||||
title: string
|
||||
deg: number
|
||||
x: number
|
||||
y: number
|
||||
vx: number
|
||||
vy: number
|
||||
r: number
|
||||
fx: number | null
|
||||
fy: number | null
|
||||
}
|
||||
interface SimLink {
|
||||
a: SimNode
|
||||
b: SimNode
|
||||
rest: number
|
||||
strength: number
|
||||
bias: number
|
||||
}
|
||||
|
||||
let simNodes: SimNode[] = []
|
||||
let simLinks: SimLink[] = []
|
||||
let bySlug = new Map<string, SimNode>()
|
||||
let neighbours = new Map<string, Set<string>>()
|
||||
let hubCut = 0 // articles with at least this many links always wear their label
|
||||
|
||||
let width = 0
|
||||
let height = 0
|
||||
let dpr = 1
|
||||
|
||||
/* the view: world point p draws at p * view.k + view.x/y */
|
||||
const view = { k: 1, x: 0, y: 0 }
|
||||
let viewTarget: { k: number; x: number; y: number } | null = null
|
||||
|
||||
const ALPHA_MIN = 0.002
|
||||
const ALPHA_DECAY = 0.021
|
||||
const VEL_DECAY = 0.55
|
||||
const REPULSE = 1100
|
||||
const GRAVITY = 0.055
|
||||
const MIN_K = 0.15
|
||||
const MAX_K = 5
|
||||
|
||||
let alpha = 1
|
||||
let alphaTarget = 0
|
||||
let raf = 0
|
||||
|
||||
let hoverNode: SimNode | null = null
|
||||
let dragNode: SimNode | null = null
|
||||
let panning = false
|
||||
let movedFar = false
|
||||
let lastPt = { x: 0, y: 0 }
|
||||
let downPt = { x: 0, y: 0 }
|
||||
|
||||
/* canvas colours follow the site theme, including accent switches */
|
||||
const colors = {
|
||||
edge: '#888',
|
||||
accent: '#4f5fe8',
|
||||
accent2: '#0ea5c9',
|
||||
halo: '#ffffff',
|
||||
label: '#5b6478',
|
||||
text: '#1b2130',
|
||||
}
|
||||
function readColors() {
|
||||
const cs = | ||||