Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
52ecf0f713 | ||
|
|
5fb521e89e | ||
|
|
bba2178496 | ||
|
|
41c373f46c | ||
|
|
7158713a2a | ||
|
|
73a68157cc | ||
|
|
bda7adc449 | ||
|
|
aa88db50b2 | ||
|
|
c9b882aa46 | ||
|
|
6368365bd6 | ||
|
|
191c99b59b | ||
|
|
b7f8e1612c |
No files matched your search
@@ -7,6 +7,67 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
## [2.18.2] - 2026-11-12
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Tables in notes and articles: words in cells were split mid-word (a narrow
|
||||||
|
first column read "Colo/r", "Blac/k") and cells had no padding or left
|
||||||
|
alignment. Tables now keep words whole and render as a card that fills the
|
||||||
|
column: raised background, rounded border, shaded header row, roomy cells,
|
||||||
|
sans-serif text at reading size, bold first column. Rendered tables are
|
||||||
|
wrapped in `<div class="table-wrap">`, which scrolls sideways on narrow
|
||||||
|
screens.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Public pages are wider: 48rem instead of 40rem (about 85 characters per
|
||||||
|
line at the reading font). Admin pages stay at 60rem.
|
||||||
|
- The site header (title, menu, search) and footer are 60rem wide on every
|
||||||
|
page, so they sit in the same place on public and admin pages; only the
|
||||||
|
content column differs.
|
||||||
|
|
||||||
|
## [2.18.1] - 2026-11-12
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- The MCP `create_note` tool says that articles live at `/article/<slug>` with a slug made from the title, so AI clients leave `slug` out unless they want a specific one
|
||||||
|
|
||||||
|
## [2.18.0] - 2026-11-12
|
||||||
|
|
||||||
|
A tidier admin area.
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- **Log page** (`/admin/log`): everything that is failing right now, newest
|
||||||
|
first. Each entry shows when it happened, what failed (crosspost, response
|
||||||
|
check, outgoing webmention, reply-context fetch, WebSub delivery,
|
||||||
|
notifications, refused silo credentials), a link to the affected post and
|
||||||
|
the error message, with Retry / Check now where that applies. It reads the
|
||||||
|
error columns the workers already keep, so an entry goes away once the
|
||||||
|
next attempt succeeds. The admin nav shows the error count.
|
||||||
|
- **Settings page** (`/admin/settings`) for site-wide settings. Notification
|
||||||
|
status and the test button live here now.
|
||||||
|
- Webmentions, Log and Settings links in the admin nav.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- The Webmentions page no longer has the Back to Dashboard button or the
|
||||||
|
Notifications section, and links to the Log instead of counting response
|
||||||
|
check errors.
|
||||||
|
|
||||||
|
## [2.17.1] - 2026-11-12
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Crossposting failed in 2.17.0 (never deployed): post URLs were built with Flask's `url_for`, which needs a web request, and crossposts run in a background worker. URLs are now built from `SITE_URL`
|
||||||
|
|
||||||
|
## [2.17.0] - 2026-11-12
|
||||||
|
|
||||||
|
Articles get URLs of their own (ADR-077).
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Articles live at `/article/<slug>` instead of `/note/<slug>`. The other address redirects (301), so links keep working when a note gains or loses a title. Feeds, pages, Micropub, crossposts, webmentions, notifications, search and the MCP tools all give the new URLs
|
||||||
|
- A new article's slug comes from its title (`Why I Left Twitter` → `why-i-left-twitter`; `-2` if taken). An `mp-slug` still wins, notes keep timestamp slugs, and slugs don't change when a title is edited later
|
||||||
|
- A Micropub update that adds or removes a title answers 201 with the post's new URL in `Location`, as the spec requires
|
||||||
|
|
||||||
## [2.16.0] - 2026-11-11
|
## [2.16.0] - 2026-11-11
|
||||||
|
|
||||||
Articles as the IndieWeb defines them: titles and summaries stored apart from the text (ADR-076).
|
Articles as the IndieWeb defines them: titles and summaries stored apart from the text (ADR-076).
|
||||||
|
|||||||
@@ -139,8 +139,8 @@ again with the new content. `_fail()` does the same.
|
|||||||
a Threads container in `ERROR`/`EXPIRED`, and Graph API auth/permission
|
a Threads container in `ERROR`/`EXPIRED`, and Graph API auth/permission
|
||||||
errors (codes 10, 190, 200).
|
errors (codes 10, 190, 200).
|
||||||
- Other errors retry after `min(30 s × 2^attempts, 6 h)`. After 8 attempts
|
- Other errors retry after `min(30 s × 2^attempts, 6 h)`. After 8 attempts
|
||||||
the row becomes `failed`. The error is shown on the edit page with a
|
the row becomes `failed`. The error is shown on the edit page and on the
|
||||||
Retry button. When a row finally fails, the owner also gets a `problems`
|
admin Log page (v2.18.0), both with a Retry button. When a row finally fails, the owner also gets a `problems`
|
||||||
notification (ADR-074).
|
notification (ADR-074).
|
||||||
- `RemoteGone` (404, or Graph error 100/33) during an update means the copy
|
- `RemoteGone` (404, or Graph error 100/33) during an update means the copy
|
||||||
was deleted remotely, so a new one is created. During a delete it counts as
|
was deleted remotely, so a new one is created. During a delete it counts as
|
||||||
@@ -273,7 +273,7 @@ reposts) that are due, each under a lease (`backfeed_claimed_until`):
|
|||||||
(`site_state.backfeed_backfill_last`). Start and finish times are in
|
(`site_state.backfeed_backfill_last`). Start and finish times are in
|
||||||
`site_state`.
|
`site_state`.
|
||||||
- **Refused credentials.** A 401/403 (or Graph auth error) puts the target
|
- **Refused credentials.** A 401/403 (or Graph auth error) puts the target
|
||||||
in `backfeed.denied` until restart; the admin Webmentions page says which
|
in `backfeed.denied` until restart; the admin Log page says which
|
||||||
scopes are needed, and a `problems` notification is sent. Crossposting
|
scopes are needed, and a `problems` notification is sent. Crossposting
|
||||||
is unaffected.
|
is unaffected.
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# ADR-062: Timestamp-Based Slug Format
|
# ADR-062: Timestamp-Based Slug Format
|
||||||
|
|
||||||
## Status
|
## Status
|
||||||
Accepted (Supersedes ADR-007)
|
Accepted (Supersedes ADR-007). Articles take their slug from the title since v2.17.0 ([ADR-077](ADR-077-article-urls-and-title-slugs.md)).
|
||||||
|
|
||||||
## Context
|
## Context
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
Accepted (v2.16.0, 2026-11-11)
|
Accepted (v2.16.0, 2026-11-11)
|
||||||
|
|
||||||
|
Article URLs (`/article/<slug>`) and title slugs: [ADR-077](ADR-077-article-urls-and-title-slugs.md) (v2.17.0).
|
||||||
|
|
||||||
Supersedes the v2.3.3 design ([micropub-title-and-source-url](../design/v2.3.3/2026-10-31-micropub-title-and-source-url.md))
|
Supersedes the v2.3.3 design ([micropub-title-and-source-url](../design/v2.3.3/2026-10-31-micropub-title-and-source-url.md))
|
||||||
and Q22's "a note has a title when its content starts with `#`". Amends
|
and Q22's "a note has a title when its content starts with `#`". Amends
|
||||||
ADR-014 (feed item titles) and ADR-040 (`p-name` and `p-summary`).
|
ADR-014 (feed item titles) and ADR-040 (`p-name` and `p-summary`).
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
# ADR-077: Article URLs and slugs from titles
|
||||||
|
|
||||||
|
## Status
|
||||||
|
|
||||||
|
Accepted (v2.17.0, 2026-11-12)
|
||||||
|
|
||||||
|
Amends ADR-062 (default slugs) for articles and ADR-076 (articles).
|
||||||
|
|
||||||
|
## Context
|
||||||
|
|
||||||
|
ADR-076 (v2.16.0) made a note with a title an article, but articles still got
|
||||||
|
a `/note/<timestamp>` URL like any other note. An article is not a note, and
|
||||||
|
its URL should say so. ADR-062 chose timestamp slugs because short notes have
|
||||||
|
no good words for a URL and their text may be private; an article has a title
|
||||||
|
written to be read, and that is the usual source of its slug on the IndieWeb.
|
||||||
|
|
||||||
|
## Decision
|
||||||
|
|
||||||
|
- **URLs.** Articles live at `/article/<slug>`, other notes at `/note/<slug>`.
|
||||||
|
`Note.permalink`, `Note.url`, `Note.endpoint` and `utils.post_path` /
|
||||||
|
`post_url` build them; nothing else writes `/note/` by hand. Slugs stay
|
||||||
|
unique across both, so a slug still names one post.
|
||||||
|
- **One URL each, the other redirects.** `/note/<slug>` for an article and
|
||||||
|
`/article/<slug>` for a note answer 301 to the right one. Adding or removing
|
||||||
|
a title changes the URL, and links made before (webmentions sent, crossposts,
|
||||||
|
bookmarks) keep working. A deleted post is 410 at either.
|
||||||
|
- **Slug from the title.** When a post is created with a title and no
|
||||||
|
`mp-slug`, the slug is the title made URL-safe (`sanitize_slug`: accents
|
||||||
|
folded, lowercase, hyphens), cut at a word boundary to 80 characters, `-2`,
|
||||||
|
`-3`… if taken, `-article` if reserved. A title with nothing usable (only
|
||||||
|
emoji, say) falls back to the timestamp slug. Notes keep timestamp slugs.
|
||||||
|
- **Slugs don't follow later title changes.** Editing an article's title, or
|
||||||
|
making a note an article, keeps its slug: a slug is the stable part of the
|
||||||
|
URL.
|
||||||
|
- **Micropub.** `Location` and `q=source` give the new URLs. Updates accept
|
||||||
|
either URL. An update that adds or removes a title answers 201 with the new
|
||||||
|
URL in `Location`, as the Micropub spec requires when a post's URL changes;
|
||||||
|
other updates are still 204.
|
||||||
|
- **Incoming webmentions** to either URL find the post.
|
||||||
|
|
||||||
|
## Consequences
|
||||||
|
|
||||||
|
- Production had no articles when this shipped, so no published URL changed.
|
||||||
|
- A note given a title later keeps its timestamp slug under `/article/`.
|
||||||
|
- Stored URLs (webmention sources, crosspost records) are not rewritten; the
|
||||||
|
redirects cover them.
|
||||||
@@ -5,8 +5,8 @@ records one decision: its context, what was decided, and the consequences.
|
|||||||
Superseded ADRs are kept as history; their Status line names the ADR that
|
Superseded ADRs are kept as history; their Status line names the ADR that
|
||||||
replaced them.
|
replaced them.
|
||||||
|
|
||||||
**Total ADR files**: 72 (71 numbers: ADR-001 to ADR-044 and ADR-050 to
|
**Total ADR files**: 73 (72 numbers: ADR-001 to ADR-044 and ADR-050 to
|
||||||
ADR-076, with two files numbered ADR-012). See [Numbering](#numbering).
|
ADR-077, with two files numbered ADR-012). See [Numbering](#numbering).
|
||||||
|
|
||||||
Status values: **Accepted** (in force), **Superseded** (replaced by a later
|
Status values: **Accepted** (in force), **Superseded** (replaced by a later
|
||||||
ADR), **Deprecated** (withdrawn, nothing replaces it; none at present),
|
ADR), **Deprecated** (withdrawn, nothing replaces it; none at present),
|
||||||
@@ -48,7 +48,7 @@ See also [database architecture](../architecture/database.md).
|
|||||||
|
|
||||||
| ADR | Title | Status | Summary |
|
| ADR | Title | Status | Summary |
|
||||||
|---|---|---|---|
|
|---|---|---|---|
|
||||||
| [062](ADR-062-timestamp-based-slug-format.md) | Timestamp-Based Slug Format | Accepted | Default slugs are `YYYYMMDDHHMMSS` timestamps (v1.5.0); replaces ADR-007. |
|
| [062](ADR-062-timestamp-based-slug-format.md) | Timestamp-Based Slug Format | Accepted* | Default slugs are `YYYYMMDDHHMMSS` timestamps (v1.5.0); replaces ADR-007. Articles take theirs from the title (ADR-077). |
|
||||||
| [035](ADR-035-custom-slugs.md) | Custom Slugs in Micropub | Accepted* | Honour `mp-slug`, sanitized, with reserved names protected (v1.1.0). |
|
| [035](ADR-035-custom-slugs.md) | Custom Slugs in Micropub | Accepted* | Honour `mp-slug`, sanitized, with reserved names protected (v1.1.0). |
|
||||||
| [034](ADR-034-full-text-search.md) | Full-Text Search with SQLite FTS5 | Accepted | FTS5 search over note content (v1.1.0). |
|
| [034](ADR-034-full-text-search.md) | Full-Text Search with SQLite FTS5 | Accepted | FTS5 search over note content (v1.1.0). |
|
||||||
| [057](ADR-057-media-attachment-model.md) | Media Attachment Model | Accepted | Social-media-style image attachments: up to 4 per note, ordered, with captions. |
|
| [057](ADR-057-media-attachment-model.md) | Media Attachment Model | Accepted | Social-media-style image attachments: up to 4 per note, ordered, with captions. |
|
||||||
@@ -69,6 +69,7 @@ See also [database architecture](../architecture/database.md).
|
|||||||
|---|---|---|---|
|
|---|---|---|---|
|
||||||
| [040](ADR-040-microformats2-compliance.md) | Strict Microformats2 Compliance | Accepted* | Full h-entry, h-card and h-feed markup (v1.3.0, reviewed v2.8.0); `p-name`/`p-summary` per ADR-076. |
|
| [040](ADR-040-microformats2-compliance.md) | Strict Microformats2 Compliance | Accepted* | Full h-entry, h-card and h-feed markup (v1.3.0, reviewed v2.8.0); `p-name`/`p-summary` per ADR-076. |
|
||||||
| [076](ADR-076-note-title-and-summary-columns.md) | Article titles and summaries stored apart from the text | Accepted | `notes.title`/`summary` columns; feeds title only articles; article previews and crossposts are title + summary (v2.16.0). |
|
| [076](ADR-076-note-title-and-summary-columns.md) | Article titles and summaries stored apart from the text | Accepted | `notes.title`/`summary` columns; feeds title only articles; article previews and crossposts are title + summary (v2.16.0). |
|
||||||
|
| [077](ADR-077-article-urls-and-title-slugs.md) | Article URLs and slugs from titles | Accepted | Articles at `/article/<slug>` with slugs from their titles; the other prefix redirects (v2.17.0). |
|
||||||
| [061](ADR-061-author-discovery.md) | Author Profile Discovery from IndieAuth | Accepted | The author h-card is read from `ADMIN_ME` and cached. |
|
| [061](ADR-061-author-discovery.md) | Author Profile Discovery from IndieAuth | Accepted | The author h-card is read from `ADMIN_ME` and cached. |
|
||||||
| [063](ADR-063-webmention-implementation.md) | Webmention Implementation | Accepted | Async receiving (202) and sending via a background worker, SSRF guard, rate limits, moderation (v1.6.0, revised up to v2.10.1). *Reconstructed.* |
|
| [063](ADR-063-webmention-implementation.md) | Webmention Implementation | Accepted | Async receiving (202) and sending via a background worker, SSRF guard, rate limits, moderation (v1.6.0, revised up to v2.10.1). *Reconstructed.* |
|
||||||
| [028](ADR-028-micropub-implementation.md) | Micropub Implementation Strategy | Accepted* | `/micropub` endpoint for creating posts (v1.0.0-rc.1); tokens now per ADR-064. |
|
| [028](ADR-028-micropub-implementation.md) | Micropub Implementation Strategy | Accepted* | `/micropub` endpoint for creating posts (v1.0.0-rc.1); tokens now per ADR-064. |
|
||||||
@@ -171,7 +172,7 @@ was carried out and is not itself superseded.
|
|||||||
|
|
||||||
## How to create a new ADR
|
## How to create a new ADR
|
||||||
|
|
||||||
1. Use the next number after the highest existing one (currently ADR-076).
|
1. Use the next number after the highest existing one (currently ADR-077).
|
||||||
2. Name it `ADR-NNN-brief-descriptive-title.md`.
|
2. Name it `ADR-NNN-brief-descriptive-title.md`.
|
||||||
3. Follow the format of recent ADRs (e.g. ADR-070, ADR-071):
|
3. Follow the format of recent ADRs (e.g. ADR-070, ADR-071):
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
# v2.17.0: Article URLs and title slugs
|
||||||
|
|
||||||
|
Implements ADR-077. Follow-up to v2.16.0 (ADR-076): articles had `/note/`
|
||||||
|
URLs and timestamp slugs.
|
||||||
|
|
||||||
|
## What changed
|
||||||
|
|
||||||
|
| Area | Change |
|
||||||
|
|---|---|
|
||||||
|
| URL helpers | `utils.post_path(slug, title)` and `post_url(slug, title)`; `Note.permalink` uses them, `Note.endpoint` (`public.article`/`public.note`) and `Note.url` (absolute) are new |
|
||||||
|
| Routes | `public.article` at `/article/<slug>`; `note` and `article` share `_permalink(slug, endpoint)`, which 301s to the other route when the post's type doesn't match. `_note_was_deleted` checks both URLs for hard-deleted posts |
|
||||||
|
| Slugs | `slug_utils.generate_title_slug(title, existing)`; `create_note` uses it for titled posts without `custom_slug`, else the timestamp slug |
|
||||||
|
| Micropub | `Location`, `q=source` url via `note.url`; `_note_from_url` accepts `/article/`; update answers 201 + `Location` when a title is added or removed |
|
||||||
|
| Other URL builders | Templates (`note.url`), webmention sending (`post_url`/`note.url`), crosspost permalink, backfeed target, notification links, search results (`article_title` from `notes.title`), MCP tools |
|
||||||
|
| Webmention receiving | `resolve_target_note` accepts `/note/` and `/article/` |
|
||||||
|
|
||||||
|
## Tests
|
||||||
|
|
||||||
|
`tests/test_articles.py::TestArticleUrls`: Micropub URL and slug, timestamp
|
||||||
|
slugs for notes, redirects both ways, updates via the old URL, slug rules
|
||||||
|
(accents, duplicates, reserved, `mp-slug`, emoji, long titles), 201 on
|
||||||
|
adding/removing a title, 410 for a deleted article, webmention targets and
|
||||||
|
homepage links, search result URLs.
|
||||||
|
|
||||||
|
## v2.17.1
|
||||||
|
|
||||||
|
`post_url` first used `url_for`, which fails outside a request (the
|
||||||
|
crosspost and backfeed workers); CI caught it in `test_likes_reposts.py`
|
||||||
|
before 2.17.0 was built. It now joins `SITE_URL` and `post_path`.
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# v2.18.1: MCP create_note describes article URLs and slugs
|
||||||
|
|
||||||
|
Documentation-only follow-up to ADR-077 (v2.17.x). The MCP `create_note`
|
||||||
|
tool description now says that a title makes the post an article at
|
||||||
|
`/article/<slug>`, that articles get their slug from the title and other
|
||||||
|
notes from the time, and that `slug` is only needed for a specific slug.
|
||||||
|
AI clients read tool descriptions to decide which arguments to send, so
|
||||||
|
this keeps them from making up a slug the title would already give.
|
||||||
|
No behaviour change.
|
||||||
@@ -468,5 +468,5 @@ def create_app(config=None):
|
|||||||
|
|
||||||
# Package version (Semantic Versioning 2.0.0)
|
# Package version (Semantic Versioning 2.0.0)
|
||||||
# See docs/standards/versioning-strategy.md for details
|
# See docs/standards/versioning-strategy.md for details
|
||||||
__version__ = "2.16.0"
|
__version__ = "2.18.2"
|
||||||
__version_info__ = (2, 16, 0)
|
__version_info__ = (2, 18, 2)
|
||||||
@@ -25,6 +25,7 @@ from typing import Dict, List, Optional
|
|||||||
from flask import current_app
|
from flask import current_app
|
||||||
|
|
||||||
from starpunk.database import get_db
|
from starpunk.database import get_db
|
||||||
|
from starpunk.utils import post_path
|
||||||
|
|
||||||
DAY = 24 * 3600
|
DAY = 24 * 3600
|
||||||
SCHEDULE = [ # (note younger than, check every), in seconds
|
SCHEDULE = [ # (note younger than, check every), in seconds
|
||||||
@@ -164,7 +165,7 @@ def _due(db, limit: int) -> list:
|
|||||||
lease = "(s.backfeed_claimed_until IS NULL OR s.backfeed_claimed_until < datetime('now'))"
|
lease = "(s.backfeed_claimed_until IS NULL OR s.backfeed_claimed_until < datetime('now'))"
|
||||||
rows = db.execute(
|
rows = db.execute(
|
||||||
f"""
|
f"""
|
||||||
SELECT s.*, n.created_at AS note_created, n.slug AS note_slug {_ELIGIBLE}
|
SELECT s.*, n.created_at AS note_created, n.slug AS note_slug, n.title AS note_title {_ELIGIBLE}
|
||||||
AND {lease}
|
AND {lease}
|
||||||
AND n.created_at >= datetime('now', ?)
|
AND n.created_at >= datetime('now', ?)
|
||||||
AND (s.backfeed_next_at IS NULL OR s.backfeed_next_at <= datetime('now'))
|
AND (s.backfeed_next_at IS NULL OR s.backfeed_next_at <= datetime('now'))
|
||||||
@@ -176,7 +177,7 @@ def _due(db, limit: int) -> list:
|
|||||||
return rows
|
return rows
|
||||||
backfill = db.execute(
|
backfill = db.execute(
|
||||||
f"""
|
f"""
|
||||||
SELECT s.*, n.created_at AS note_created, n.slug AS note_slug {_ELIGIBLE}
|
SELECT s.*, n.created_at AS note_created, n.slug AS note_slug, n.title AS note_title {_ELIGIBLE}
|
||||||
AND {lease} AND s.backfeed_backfill = 1
|
AND {lease} AND s.backfeed_backfill = 1
|
||||||
AND (s.backfeed_next_at IS NULL OR s.backfeed_next_at <= datetime('now'))
|
AND (s.backfeed_next_at IS NULL OR s.backfeed_next_at <= datetime('now'))
|
||||||
ORDER BY s.id LIMIT 1
|
ORDER BY s.id LIMIT 1
|
||||||
@@ -381,7 +382,7 @@ def check(row, target) -> None:
|
|||||||
# older note (e.g. one linked after the fact). ADR-074 Decision 5.
|
# older note (e.g. one linked after the fact). ADR-074 Decision 5.
|
||||||
quiet = bool(row["backfeed_backfill"]) or (
|
quiet = bool(row["backfeed_backfill"]) or (
|
||||||
row["backfeed_checked_at"] is None and _age_seconds(row["note_created"]) > DAY)
|
row["backfeed_checked_at"] is None and _age_seconds(row["note_created"]) > DAY)
|
||||||
store(db, row["note_id"], f"{site}/note/{row['note_slug']}", row["target"], harvest, quiet=quiet)
|
store(db, row["note_id"], site + post_path(row["note_slug"], row["note_title"]), row["target"], harvest, quiet=quiet)
|
||||||
_store_counts(db, row["id"], hidden_counts(harvest))
|
_store_counts(db, row["id"], hidden_counts(harvest))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,127 @@
|
|||||||
|
"""
|
||||||
|
Error log for the admin Log page (v2.18.0)
|
||||||
|
|
||||||
|
Collects what is failing right now from the tables that already record it:
|
||||||
|
crossposts, response checks (backfeed), outgoing webmentions, reply-context
|
||||||
|
fetches, WebSub deliveries and notifications. Nothing new is stored. An entry
|
||||||
|
disappears once the next attempt succeeds, so the page lists only problems
|
||||||
|
that still need attention.
|
||||||
|
|
||||||
|
Each entry is a dict:
|
||||||
|
when -- timestamp text (UTC) or "" when unknown
|
||||||
|
area -- short label, e.g. "Crosspost to Bluesky"
|
||||||
|
note -- the affected Note, or None for site-wide problems
|
||||||
|
detail -- extra context (a URL or "retrying"), may be ""
|
||||||
|
error -- the recorded error message
|
||||||
|
action -- optional (endpoint, id, label) for a retry button
|
||||||
|
"""
|
||||||
|
|
||||||
|
from flask import current_app
|
||||||
|
|
||||||
|
from starpunk.database import get_db
|
||||||
|
|
||||||
|
SILOS = {"gotosocial": "GoToSocial", "bluesky": "Bluesky", "threads": "Threads"}
|
||||||
|
|
||||||
|
|
||||||
|
def _silo(target: str) -> str:
|
||||||
|
return SILOS.get(target, target)
|
||||||
|
|
||||||
|
|
||||||
|
def _notes(ids) -> dict:
|
||||||
|
"""Load the affected notes once each (deleted notes come back as None)"""
|
||||||
|
from starpunk.notes import get_note
|
||||||
|
|
||||||
|
return {i: get_note(id=i) for i in set(ids) if i is not None}
|
||||||
|
|
||||||
|
|
||||||
|
def entries() -> list:
|
||||||
|
"""Every current error, newest first; site-wide problems come first"""
|
||||||
|
from starpunk import backfeed, notifications
|
||||||
|
|
||||||
|
db = get_db(current_app)
|
||||||
|
rows = []
|
||||||
|
|
||||||
|
for r in db.execute(
|
||||||
|
"SELECT id, note_id, target, state, last_error, updated_at FROM syndications "
|
||||||
|
"WHERE last_error IS NOT NULL AND state != 'synced'"
|
||||||
|
):
|
||||||
|
rows.append({
|
||||||
|
"when": r["updated_at"], "area": f"Crosspost to {_silo(r['target'])}",
|
||||||
|
"note_id": r["note_id"], "detail": "retrying" if r["state"] == "pending" else "",
|
||||||
|
"error": r["last_error"],
|
||||||
|
"action": ("admin.retry_syndication", r["id"], "Retry"),
|
||||||
|
})
|
||||||
|
|
||||||
|
for r in db.execute(
|
||||||
|
"SELECT id, note_id, target, backfeed_error, backfeed_checked_at, remote_url FROM syndications "
|
||||||
|
"WHERE backfeed_error IS NOT NULL"
|
||||||
|
):
|
||||||
|
rows.append({
|
||||||
|
"when": r["backfeed_checked_at"], "area": f"Response check on {_silo(r['target'])}",
|
||||||
|
"note_id": r["note_id"], "detail": r["remote_url"] or "", "error": r["backfeed_error"],
|
||||||
|
"action": ("admin.check_syndication_responses", r["id"], "Check now"),
|
||||||
|
})
|
||||||
|
|
||||||
|
for r in db.execute(
|
||||||
|
"SELECT source_note_id, target_url, status, last_error, COALESCE(started_at, created_at) AS at "
|
||||||
|
"FROM webmention_queue WHERE last_error IS NOT NULL AND status IN ('pending', 'failed')"
|
||||||
|
):
|
||||||
|
rows.append({
|
||||||
|
"when": r["at"], "area": "Webmention sent", "note_id": r["source_note_id"],
|
||||||
|
"detail": r["target_url"] + (" (retrying)" if r["status"] == "pending" else ""),
|
||||||
|
"error": r["last_error"], "action": None,
|
||||||
|
})
|
||||||
|
|
||||||
|
for r in db.execute(
|
||||||
|
"SELECT n.id AS note_id, rc.url, rc.fetch_error, rc.fetched_at, rc.created_at "
|
||||||
|
"FROM reply_contexts rc JOIN notes n ON n.in_reply_to = rc.url "
|
||||||
|
"WHERE rc.fetch_status = 'error' AND n.deleted_at IS NULL"
|
||||||
|
):
|
||||||
|
rows.append({
|
||||||
|
"when": r["fetched_at"] or r["created_at"], "area": "Reply context fetch",
|
||||||
|
"note_id": r["note_id"], "detail": r["url"], "error": r["fetch_error"] or "fetch failed",
|
||||||
|
"action": None,
|
||||||
|
})
|
||||||
|
|
||||||
|
for r in db.execute(
|
||||||
|
"SELECT topic, callback, last_error, COALESCE(last_success_at, verified_at, created_at) AS at "
|
||||||
|
"FROM websub_subscriptions WHERE last_error IS NOT NULL"
|
||||||
|
):
|
||||||
|
rows.append({
|
||||||
|
"when": r["at"], "area": "WebSub delivery", "note_id": None,
|
||||||
|
"detail": f"{r['topic']} → {r['callback']}", "error": r["last_error"], "action": None,
|
||||||
|
})
|
||||||
|
|
||||||
|
rows.sort(key=lambda e: str(e["when"] or ""), reverse=True)
|
||||||
|
|
||||||
|
site = []
|
||||||
|
for silo, message in backfeed.denied.items():
|
||||||
|
site.append({"when": "", "area": f"Response checks on {_silo(silo)}", "note_id": None,
|
||||||
|
"detail": "paused", "error": message, "action": None})
|
||||||
|
notify_error = notifications.last_error(db)
|
||||||
|
if notify_error:
|
||||||
|
when, _, message = notify_error.partition(" UTC ")
|
||||||
|
site.append({"when": when if message else "", "area": "Notifications", "note_id": None,
|
||||||
|
"detail": "", "error": message or notify_error, "action": None})
|
||||||
|
|
||||||
|
entries = site + rows
|
||||||
|
notes = _notes(e["note_id"] for e in entries)
|
||||||
|
for e in entries:
|
||||||
|
e["note"] = notes.get(e.pop("note_id"))
|
||||||
|
return entries
|
||||||
|
|
||||||
|
|
||||||
|
def count() -> int:
|
||||||
|
"""Cheap total for the admin nav badge"""
|
||||||
|
from starpunk import backfeed, notifications
|
||||||
|
|
||||||
|
db = get_db(current_app)
|
||||||
|
total = db.execute(
|
||||||
|
"SELECT (SELECT COUNT(*) FROM syndications WHERE last_error IS NOT NULL AND state != 'synced')"
|
||||||
|
" + (SELECT COUNT(*) FROM syndications WHERE backfeed_error IS NOT NULL)"
|
||||||
|
" + (SELECT COUNT(*) FROM webmention_queue WHERE last_error IS NOT NULL AND status IN ('pending', 'failed'))"
|
||||||
|
" + (SELECT COUNT(*) FROM reply_contexts rc JOIN notes n ON n.in_reply_to = rc.url"
|
||||||
|
" WHERE rc.fetch_status = 'error' AND n.deleted_at IS NULL)"
|
||||||
|
" + (SELECT COUNT(*) FROM websub_subscriptions WHERE last_error IS NOT NULL)"
|
||||||
|
).fetchone()[0]
|
||||||
|
return total + len(backfeed.denied) + (1 if notifications.last_error(db) else 0)
|
||||||
@@ -60,17 +60,17 @@ def _clamp(limit: int) -> int:
|
|||||||
return max(1, min(int(limit), MAX_LIMIT))
|
return max(1, min(int(limit), MAX_LIMIT))
|
||||||
|
|
||||||
|
|
||||||
def _note_url(slug: str) -> str:
|
def _note_url(slug: str, title=None) -> str:
|
||||||
from starpunk.utils import absolute_url_for
|
from starpunk.utils import post_url
|
||||||
|
|
||||||
return absolute_url_for("public.note", slug=slug)
|
return post_url(slug, title)
|
||||||
|
|
||||||
|
|
||||||
def _summary(note) -> dict:
|
def _summary(note) -> dict:
|
||||||
from starpunk.utils import iso_utc
|
from starpunk.utils import iso_utc
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"url": _note_url(note.slug),
|
"url": note.url,
|
||||||
"slug": note.slug,
|
"slug": note.slug,
|
||||||
"title": note.title,
|
"title": note.title,
|
||||||
"summary": note.summary,
|
"summary": note.summary,
|
||||||
@@ -139,7 +139,7 @@ def register_tools(server: MCPServer, app: Flask) -> None:
|
|||||||
results = fts(query=query, db_path=db_path, published_only=not include_drafts, limit=_clamp(limit))
|
results = fts(query=query, db_path=db_path, published_only=not include_drafts, limit=_clamp(limit))
|
||||||
return {
|
return {
|
||||||
"results": [
|
"results": [
|
||||||
{"url": _note_url(r["slug"]), "slug": r["slug"], "title": r.get("title"),
|
{"url": _note_url(r["slug"], r.get("article_title")), "slug": r["slug"], "title": r.get("title"),
|
||||||
"snippet": r.get("snippet")}
|
"snippet": r.get("snippet")}
|
||||||
for r in results
|
for r in results
|
||||||
]
|
]
|
||||||
@@ -176,7 +176,7 @@ def register_tools(server: MCPServer, app: Flask) -> None:
|
|||||||
note = _find_note(url_or_slug)
|
note = _find_note(url_or_slug)
|
||||||
if not note.published and not _sees_drafts(info):
|
if not note.published and not _sees_drafts(info):
|
||||||
raise ToolError("Note not found")
|
raise ToolError("Note not found")
|
||||||
return {"url": _note_url(note.slug), "slug": note.slug,
|
return {"url": note.url, "slug": note.slug,
|
||||||
"properties": note_to_mf2(note)["properties"]}
|
"properties": note_to_mf2(note)["properties"]}
|
||||||
|
|
||||||
return await run(one)
|
return await run(one)
|
||||||
@@ -232,9 +232,11 @@ def register_tools(server: MCPServer, app: Flask) -> None:
|
|||||||
) -> dict:
|
) -> dict:
|
||||||
"""Create a note (Markdown). It is a draft unless draft is false;
|
"""Create a note (Markdown). It is a draft unless draft is false;
|
||||||
publishing makes it public and crossposts it to the syndicate_to
|
publishing makes it public and crossposts it to the syndicate_to
|
||||||
targets. A title makes it an article; summary is its short summary,
|
targets. A title makes it an article, at /article/<slug>; summary is its
|
||||||
shown on the homepage and in feeds and crossposts. At most one of like_of,
|
short summary, shown on the homepage and in feeds and crossposts. The
|
||||||
repost_of and bookmark_of. published_at is an ISO 8601 date."""
|
slug is made from the title for articles and from the time for other
|
||||||
|
notes, so leave slug out unless a specific one is wanted. At most one of
|
||||||
|
like_of, repost_of and bookmark_of. published_at is an ISO 8601 date."""
|
||||||
info = _token_info()
|
info = _token_info()
|
||||||
_require(info, "create", "draft")
|
_require(info, "create", "draft")
|
||||||
|
|
||||||
@@ -314,7 +316,7 @@ def register_tools(server: MCPServer, app: Flask) -> None:
|
|||||||
from starpunk.micropub import handle_update
|
from starpunk.micropub import handle_update
|
||||||
|
|
||||||
note = _find_note(url)
|
note = _find_note(url)
|
||||||
data["url"] = _note_url(note.slug)
|
data["url"] = note.url
|
||||||
handle_update(data, info)
|
handle_update(data, info)
|
||||||
return _status_after(data["url"])
|
return _status_after(data["url"])
|
||||||
|
|
||||||
@@ -329,7 +331,7 @@ def register_tools(server: MCPServer, app: Flask) -> None:
|
|||||||
def delete():
|
def delete():
|
||||||
from starpunk.micropub import handle_delete
|
from starpunk.micropub import handle_delete
|
||||||
|
|
||||||
note_url = _note_url(_find_note(url).slug)
|
note_url = _find_note(url).url
|
||||||
handle_delete({"url": note_url}, info)
|
handle_delete({"url": note_url}, info)
|
||||||
return {"url": note_url, "status": "deleted"}
|
return {"url": note_url, "status": "deleted"}
|
||||||
|
|
||||||
|
|||||||
@@ -549,7 +549,7 @@ def _check_type(data: dict) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def _note_from_url(url: Optional[str], deleted: bool = False):
|
def _note_from_url(url: Optional[str], deleted: bool = False):
|
||||||
"""Find the note a URL points at (/note/<slug> on this site)"""
|
"""Find the note a URL points at (/note/<slug> or /article/<slug> on this site)"""
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
from starpunk.database import get_db
|
from starpunk.database import get_db
|
||||||
|
|
||||||
@@ -560,7 +560,7 @@ def _note_from_url(url: Optional[str], deleted: bool = False):
|
|||||||
if parsed.netloc and site.netloc and parsed.netloc != site.netloc:
|
if parsed.netloc and site.netloc and parsed.netloc != site.netloc:
|
||||||
raise MicropubValidationError("URL is not on this site")
|
raise MicropubValidationError("URL is not on this site")
|
||||||
parts = [p for p in parsed.path.split("/") if p]
|
parts = [p for p in parsed.path.split("/") if p]
|
||||||
if len(parts) != 2 or parts[0] not in ("note", "notes"):
|
if len(parts) != 2 or parts[0] not in ("note", "notes", "article", "articles"):
|
||||||
raise MicropubValidationError("URL is not a post on this site")
|
raise MicropubValidationError("URL is not a post on this site")
|
||||||
slug = parts[1]
|
slug = parts[1]
|
||||||
if deleted:
|
if deleted:
|
||||||
@@ -678,7 +678,7 @@ def handle_create(data: dict, token_info: dict, files=None):
|
|||||||
from starpunk.syndication import resolve_targets, select_targets
|
from starpunk.syndication import resolve_targets, select_targets
|
||||||
select_targets(note.id, resolve_targets(requested_targets))
|
select_targets(note.id, resolve_targets(requested_targets))
|
||||||
|
|
||||||
return "", 201, {"Location": absolute_url_for("public.note", slug=note.slug)}
|
return "", 201, {"Location": note.url}
|
||||||
|
|
||||||
except InvalidNoteDataError as e:
|
except InvalidNoteDataError as e:
|
||||||
raise MicropubValidationError(str(e))
|
raise MicropubValidationError(str(e))
|
||||||
@@ -820,6 +820,11 @@ def handle_update(data: dict, token_info: dict):
|
|||||||
current_app.logger.error(f"Failed to update note via Micropub: {e}")
|
current_app.logger.error(f"Failed to update note via Micropub: {e}")
|
||||||
raise MicropubError("server_error", "Failed to update post", status_code=500)
|
raise MicropubError("server_error", "Failed to update post", status_code=500)
|
||||||
|
|
||||||
|
# Adding or removing a title moves the post between /note/ and /article/:
|
||||||
|
# the spec says to answer 201 with the new URL (v2.17.0)
|
||||||
|
if bool(title) != bool(note.title):
|
||||||
|
from starpunk.utils import post_url
|
||||||
|
return "", 201, {"Location": post_url(note.slug, title)}
|
||||||
return "", 204
|
return "", 204
|
||||||
|
|
||||||
|
|
||||||
@@ -860,7 +865,7 @@ def note_to_mf2(note, wanted: Optional[list] = None) -> dict:
|
|||||||
# HTML-authored content comes back as HTML (3.7.2, v2.9.0)
|
# HTML-authored content comes back as HTML (3.7.2, v2.9.0)
|
||||||
"content": [{"html": content} if note.content_format == "html" else content],
|
"content": [{"html": content} if note.content_format == "html" else content],
|
||||||
"published": [iso_utc(note.created_at)],
|
"published": [iso_utc(note.created_at)],
|
||||||
"url": [absolute_url_for("public.note", slug=note.slug)],
|
"url": [note.url],
|
||||||
"post-status": ["published" if note.published else "draft"],
|
"post-status": ["published" if note.published else "draft"],
|
||||||
}
|
}
|
||||||
if note.title:
|
if note.title:
|
||||||
|
|||||||
+22
-7
@@ -62,7 +62,9 @@ ALLOWED_ATTRIBUTES = {
|
|||||||
def render_markdown(text: str) -> str:
|
def render_markdown(text: str) -> str:
|
||||||
"""Note Markdown (or HTML) to sanitized HTML"""
|
"""Note Markdown (or HTML) to sanitized HTML"""
|
||||||
html = markdown.markdown(text, extensions=MARKDOWN_EXTENSIONS)
|
html = markdown.markdown(text, extensions=MARKDOWN_EXTENSIONS)
|
||||||
return nh3.clean(html, tags=ALLOWED_TAGS, attributes=ALLOWED_ATTRIBUTES)
|
html = nh3.clean(html, tags=ALLOWED_TAGS, attributes=ALLOWED_ATTRIBUTES)
|
||||||
|
# A wrapper lets a table fill the column yet scroll sideways when too wide (v2.18.2)
|
||||||
|
return re.sub(r"<table\b", '<div class="table-wrap"><table', html).replace("</table>", "</table></div>")
|
||||||
|
|
||||||
|
|
||||||
# Likes, reposts and bookmarks (v2.5.0, v2.9.0)
|
# Likes, reposts and bookmarks (v2.5.0, v2.9.0)
|
||||||
@@ -383,14 +385,27 @@ class Note:
|
|||||||
"""
|
"""
|
||||||
Generate permalink (public URL path)
|
Generate permalink (public URL path)
|
||||||
|
|
||||||
Returns:
|
Articles (notes with a title) live under /article/, other notes
|
||||||
URL path string (e.g., '/note/my-first-note')
|
under /note/ (v2.17.0).
|
||||||
|
|
||||||
Examples:
|
Returns:
|
||||||
>>> note.permalink
|
URL path string (e.g., '/note/my-first-note', '/article/my-essay')
|
||||||
'/note/my-first-note'
|
|
||||||
"""
|
"""
|
||||||
return f"/note/{self.slug}"
|
from starpunk.utils import post_path
|
||||||
|
|
||||||
|
return post_path(self.slug, self.title)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def endpoint(self) -> str:
|
||||||
|
"""The route that shows this note: public.article or public.note (v2.17.0)"""
|
||||||
|
return "public.article" if self.title else "public.note"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def url(self) -> str:
|
||||||
|
"""Absolute permalink, built from SITE_URL (needs an app context)"""
|
||||||
|
from starpunk.utils import post_url
|
||||||
|
|
||||||
|
return post_url(self.slug, self.title)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_published(self) -> bool:
|
def is_published(self) -> bool:
|
||||||
|
|||||||
+8
-5
@@ -40,6 +40,7 @@ from starpunk.utils import (
|
|||||||
calculate_content_hash,
|
calculate_content_hash,
|
||||||
validate_note_path,
|
validate_note_path,
|
||||||
validate_slug,
|
validate_slug,
|
||||||
|
post_url,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -250,9 +251,11 @@ def create_note(
|
|||||||
if not success:
|
if not success:
|
||||||
raise InvalidNoteDataError("slug", custom_slug, error)
|
raise InvalidNoteDataError("slug", custom_slug, error)
|
||||||
else:
|
else:
|
||||||
# Generate timestamp-based slug (ADR-062)
|
# Articles take their slug from the title (v2.17.0); other notes, or a
|
||||||
from starpunk.slug_utils import generate_timestamp_slug
|
# title with nothing usable in it, get a timestamp slug (ADR-062)
|
||||||
slug = generate_timestamp_slug(created_at, existing_slugs)
|
from starpunk.slug_utils import generate_timestamp_slug, generate_title_slug
|
||||||
|
slug = (generate_title_slug(title, existing_slugs) if title else None) \
|
||||||
|
or generate_timestamp_slug(created_at, existing_slugs)
|
||||||
|
|
||||||
# 4. GENERATE FILE PATH
|
# 4. GENERATE FILE PATH
|
||||||
note_path = generate_note_path(slug, created_at, data_dir)
|
note_path = generate_note_path(slug, created_at, data_dir)
|
||||||
@@ -348,7 +351,7 @@ def create_note(
|
|||||||
db_path = Path(current_app.config["DATABASE_PATH"])
|
db_path = Path(current_app.config["DATABASE_PATH"])
|
||||||
site_url = current_app.config["SITE_URL"]
|
site_url = current_app.config["SITE_URL"]
|
||||||
from starpunk.utils import absolute_url_for
|
from starpunk.utils import absolute_url_for
|
||||||
note_url = absolute_url_for("public.note", slug=slug)
|
note_url = post_url(slug, title)
|
||||||
|
|
||||||
# Get rendered HTML from note
|
# Get rendered HTML from note
|
||||||
html_content = note.html
|
html_content = note.html
|
||||||
@@ -903,7 +906,7 @@ def update_note(
|
|||||||
db_path = Path(current_app.config["DATABASE_PATH"])
|
db_path = Path(current_app.config["DATABASE_PATH"])
|
||||||
site_url = current_app.config["SITE_URL"]
|
site_url = current_app.config["SITE_URL"]
|
||||||
from starpunk.utils import absolute_url_for
|
from starpunk.utils import absolute_url_for
|
||||||
note_url = absolute_url_for("public.note", slug=updated_note.slug)
|
note_url = updated_note.url
|
||||||
|
|
||||||
# Get rendered HTML from updated note (if published)
|
# Get rendered HTML from updated note (if published)
|
||||||
html_content = updated_note.html if updated_note.published else None
|
html_content = updated_note.html if updated_note.published else None
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ import time
|
|||||||
from typing import Dict, List, Optional, Tuple
|
from typing import Dict, List, Optional, Tuple
|
||||||
from urllib.parse import parse_qsl, urlsplit
|
from urllib.parse import parse_qsl, urlsplit
|
||||||
|
|
||||||
|
from starpunk.utils import post_path
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
RESPONSE_EVENTS = ("reply", "mention", "quote", "like", "repost", "bookmark")
|
RESPONSE_EVENTS = ("reply", "mention", "quote", "like", "repost", "bookmark")
|
||||||
@@ -158,7 +160,7 @@ def _messages(rows, site_url: str, conn) -> List[Tuple[str, str, List[int]]]:
|
|||||||
who = (row["author_name"] or "someone") + (f" via {via}" if via else "")
|
who = (row["author_name"] or "someone") + (f" via {via}" if via else "")
|
||||||
pending = row["moderation_status"] == "pending"
|
pending = row["moderation_status"] == "pending"
|
||||||
link = (f"{site}/admin/webmentions/{row['id']}" if pending
|
link = (f"{site}/admin/webmentions/{row['id']}" if pending
|
||||||
else f"{site}/note/{row['slug']}#responses")
|
else f"{site}{post_path(row['slug'], row['note_title'])}#responses")
|
||||||
if row["mention_type"] in GROUPED:
|
if row["mention_type"] in GROUPED:
|
||||||
groups.setdefault((row["target_note_id"], row["mention_type"], row["slug"], pending), []).append(
|
groups.setdefault((row["target_note_id"], row["mention_type"], row["slug"], pending), []).append(
|
||||||
(row["id"], row["author_name"] or "someone", link))
|
(row["id"], row["author_name"] or "someone", link))
|
||||||
@@ -206,7 +208,7 @@ class Sweeper:
|
|||||||
logger.warning(f"Dropped {dropped} notification(s) older than {DROP_AFTER_HOURS} hours")
|
logger.warning(f"Dropped {dropped} notification(s) older than {DROP_AFTER_HOURS} hours")
|
||||||
rows = conn.execute(
|
rows = conn.execute(
|
||||||
"""
|
"""
|
||||||
SELECT w.*, n.slug FROM webmentions w JOIN notes n ON n.id = w.target_note_id
|
SELECT w.*, n.slug, n.title AS note_title FROM webmentions w JOIN notes n ON n.id = w.target_note_id
|
||||||
WHERE w.notified_at IS NULL AND w.validation_status = 'valid'
|
WHERE w.notified_at IS NULL AND w.validation_status = 'valid'
|
||||||
AND w.moderation_status IN ('approved', 'pending')
|
AND w.moderation_status IN ('approved', 'pending')
|
||||||
ORDER BY w.id LIMIT 100
|
ORDER BY w.id LIMIT 100
|
||||||
|
|||||||
@@ -25,6 +25,20 @@ from starpunk.notes import (
|
|||||||
bp = Blueprint("admin", __name__, url_prefix="/admin")
|
bp = Blueprint("admin", __name__, url_prefix="/admin")
|
||||||
|
|
||||||
|
|
||||||
|
@bp.context_processor
|
||||||
|
def _admin_nav():
|
||||||
|
"""Error count for the Log link in the admin nav (v2.18.0)"""
|
||||||
|
if not getattr(g, "me", None):
|
||||||
|
return {}
|
||||||
|
from starpunk import error_log
|
||||||
|
|
||||||
|
try:
|
||||||
|
return {"error_count": error_log.count()}
|
||||||
|
except Exception as e: # never break an admin page over the badge
|
||||||
|
logger.warning(f"Could not count errors for the admin nav: {e}")
|
||||||
|
return {"error_count": 0}
|
||||||
|
|
||||||
|
|
||||||
@bp.route("/")
|
@bp.route("/")
|
||||||
@require_auth
|
@require_auth
|
||||||
def dashboard():
|
def dashboard():
|
||||||
@@ -530,7 +544,6 @@ def webmentions():
|
|||||||
status_filter=status_filter,
|
status_filter=status_filter,
|
||||||
origin_filter=origin_filter,
|
origin_filter=origin_filter,
|
||||||
backfeed=backfeed.status(),
|
backfeed=backfeed.status(),
|
||||||
notify=_notify_status(),
|
|
||||||
page=page,
|
page=page,
|
||||||
total_pages=total_pages,
|
total_pages=total_pages,
|
||||||
user_me=g.me
|
user_me=g.me
|
||||||
@@ -698,7 +711,7 @@ def revoke_token(token_id):
|
|||||||
|
|
||||||
|
|
||||||
def _notify_status() -> dict:
|
def _notify_status() -> dict:
|
||||||
"""Notification settings and last error for the Webmentions page (v2.14.0)"""
|
"""Notification settings and last error for the Settings page (v2.14.0)"""
|
||||||
from starpunk import notifications
|
from starpunk import notifications
|
||||||
from starpunk.database import get_db
|
from starpunk.database import get_db
|
||||||
|
|
||||||
@@ -711,6 +724,22 @@ def _notify_status() -> dict:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route("/settings")
|
||||||
|
@require_auth
|
||||||
|
def settings():
|
||||||
|
"""Site settings: notifications (v2.18.0). Template: templates/admin/settings.html"""
|
||||||
|
return render_template("admin/settings.html", notify=_notify_status(), user_me=g.me)
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route("/log")
|
||||||
|
@require_auth
|
||||||
|
def error_log():
|
||||||
|
"""Current errors with the affected note (v2.18.0). Template: templates/admin/log.html"""
|
||||||
|
from starpunk import error_log as log
|
||||||
|
|
||||||
|
return render_template("admin/log.html", entries=log.entries(), user_me=g.me)
|
||||||
|
|
||||||
|
|
||||||
@bp.route("/notifications/test", methods=["POST"])
|
@bp.route("/notifications/test", methods=["POST"])
|
||||||
@require_auth
|
@require_auth
|
||||||
def notifications_test():
|
def notifications_test():
|
||||||
@@ -722,7 +751,7 @@ def notifications_test():
|
|||||||
notifications._record(current_app.config["DATABASE_PATH"], ok, error)
|
notifications._record(current_app.config["DATABASE_PATH"], ok, error)
|
||||||
flash("Test notification sent" if ok else f"Test notification failed: {error or 'unknown error'}",
|
flash("Test notification sent" if ok else f"Test notification failed: {error or 'unknown error'}",
|
||||||
"success" if ok else "error")
|
"success" if ok else "error")
|
||||||
return redirect(url_for("admin.webmentions"))
|
return redirect(url_for("admin.settings"))
|
||||||
|
|
||||||
|
|
||||||
@bp.route("/backfeed/backfill", methods=["POST"])
|
@bp.route("/backfeed/backfill", methods=["POST"])
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ No authentication required for these routes.
|
|||||||
import hashlib
|
import hashlib
|
||||||
from datetime import datetime, timedelta, timezone
|
from datetime import datetime, timedelta, timezone
|
||||||
|
|
||||||
from flask import Blueprint, abort, render_template, Response, current_app, request, send_from_directory
|
from flask import Blueprint, abort, redirect, render_template, Response, current_app, request, send_from_directory, url_for
|
||||||
|
|
||||||
from starpunk.notes import list_notes, get_note
|
from starpunk.notes import list_notes, get_note
|
||||||
from starpunk.websub import embed_hub
|
from starpunk.websub import embed_hub
|
||||||
@@ -354,18 +354,30 @@ def _note_was_deleted(slug: str) -> bool:
|
|||||||
).fetchone():
|
).fetchone():
|
||||||
return True
|
return True
|
||||||
return db.execute(
|
return db.execute(
|
||||||
"SELECT 1 FROM webmention_queue WHERE source_url = ? AND source_note_id IS NULL",
|
"SELECT 1 FROM webmention_queue WHERE source_url IN (?, ?) AND source_note_id IS NULL",
|
||||||
(absolute_url_for("public.note", slug=slug),),
|
(absolute_url_for("public.note", slug=slug), absolute_url_for("public.article", slug=slug)),
|
||||||
).fetchone() is not None
|
).fetchone() is not None
|
||||||
|
|
||||||
|
|
||||||
@bp.route("/note/<slug>")
|
@bp.route("/note/<slug>")
|
||||||
def note(slug: str):
|
def note(slug: str):
|
||||||
|
"""A note's permalink page; an article's /note/ URL redirects to /article/"""
|
||||||
|
return _permalink(slug, "public.note")
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route("/article/<slug>")
|
||||||
|
def article(slug: str):
|
||||||
|
"""An article's permalink page (v2.17.0); a note's /article/ URL redirects to /note/"""
|
||||||
|
return _permalink(slug, "public.article")
|
||||||
|
|
||||||
|
|
||||||
|
def _permalink(slug: str, endpoint: str):
|
||||||
"""
|
"""
|
||||||
Individual note permalink page
|
Individual note or article permalink page
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
slug: URL-safe note identifier
|
slug: URL-safe note identifier
|
||||||
|
endpoint: The route the request came in on
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Rendered note template with full content
|
Rendered note template with full content
|
||||||
@@ -390,6 +402,12 @@ def note(slug: str):
|
|||||||
abort(410)
|
abort(410)
|
||||||
abort(404)
|
abort(404)
|
||||||
|
|
||||||
|
# Each post has one URL: /article/ for articles, /note/ for notes (v2.17.0).
|
||||||
|
# The other one redirects, so links made before a title was added or
|
||||||
|
# removed keep working.
|
||||||
|
if note_obj.endpoint != endpoint:
|
||||||
|
return redirect(url_for(note_obj.endpoint, slug=slug), code=301)
|
||||||
|
|
||||||
# Get media for note (v1.2.0 Phase 3)
|
# Get media for note (v1.2.0 Phase 3)
|
||||||
media = get_note_media(note_obj.id)
|
media = get_note_media(note_obj.id)
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ from pathlib import Path
|
|||||||
from flask import Blueprint, current_app, g, jsonify, render_template, request
|
from flask import Blueprint, current_app, g, jsonify, render_template, request
|
||||||
|
|
||||||
from starpunk.search import has_fts_table, search_notes
|
from starpunk.search import has_fts_table, search_notes
|
||||||
|
from starpunk.utils import post_path
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -108,7 +109,7 @@ def api_search():
|
|||||||
"title": r["title"] or f"Note from {r['created_at'][:10]}",
|
"title": r["title"] or f"Note from {r['created_at'][:10]}",
|
||||||
"excerpt": r["snippet"], # Already has <mark> tags
|
"excerpt": r["snippet"], # Already has <mark> tags
|
||||||
"published_at": r["created_at"],
|
"published_at": r["created_at"],
|
||||||
"url": f"/note/{r['slug']}",
|
"url": post_path(r["slug"], r.get("article_title")),
|
||||||
}
|
}
|
||||||
for r in results
|
for r in results
|
||||||
],
|
],
|
||||||
@@ -176,7 +177,7 @@ def search_page():
|
|||||||
"title": r["title"] or f"Note from {r['created_at'][:10]}",
|
"title": r["title"] or f"Note from {r['created_at'][:10]}",
|
||||||
"excerpt": Markup(safe_snippet), # Mark as safe since we've escaped it ourselves
|
"excerpt": Markup(safe_snippet), # Mark as safe since we've escaped it ourselves
|
||||||
"published_at": r["created_at"],
|
"published_at": r["created_at"],
|
||||||
"url": f"/note/{r['slug']}",
|
"url": post_path(r["slug"], r.get("article_title")),
|
||||||
})
|
})
|
||||||
results = formatted_results
|
results = formatted_results
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -139,9 +139,10 @@ def resolve_target_note(target_url: str) -> int | None:
|
|||||||
# Strip query params and fragments for matching
|
# Strip query params and fragments for matching
|
||||||
target_path = target_parsed.path.rstrip('/')
|
target_path = target_parsed.path.rstrip('/')
|
||||||
|
|
||||||
# Check if it's a note URL pattern: /note/{slug}
|
# A note or article URL: /note/{slug} or /article/{slug} (v2.17.0).
|
||||||
if target_path.startswith('/note/'):
|
# Either prefix finds the post, as the page redirects to the right one.
|
||||||
slug = target_path[6:] # Remove '/note/' prefix
|
prefix, _, slug = target_path.lstrip('/').partition('/')
|
||||||
|
if prefix in ('note', 'article') and '/' not in slug:
|
||||||
if slug:
|
if slug:
|
||||||
try:
|
try:
|
||||||
note = get_note(slug=slug)
|
note = get_note(slug=slug)
|
||||||
|
|||||||
@@ -330,6 +330,7 @@ def search_notes_fts5(
|
|||||||
notes.id,
|
notes.id,
|
||||||
notes.slug,
|
notes.slug,
|
||||||
notes_fts.title,
|
notes_fts.title,
|
||||||
|
notes.title AS article_title,
|
||||||
notes.published,
|
notes.published,
|
||||||
notes.created_at,
|
notes.created_at,
|
||||||
rank AS relevance,
|
rank AS relevance,
|
||||||
@@ -356,6 +357,7 @@ def search_notes_fts5(
|
|||||||
'id': row['id'],
|
'id': row['id'],
|
||||||
'slug': row['slug'],
|
'slug': row['slug'],
|
||||||
'title': row['title'],
|
'title': row['title'],
|
||||||
|
'article_title': row['article_title'],
|
||||||
'snippet': row['snippet'], # Plain string - route must escape HTML while preserving <mark> tags
|
'snippet': row['snippet'], # Plain string - route must escape HTML while preserving <mark> tags
|
||||||
'relevance': row['relevance'],
|
'relevance': row['relevance'],
|
||||||
'published': bool(row['published']),
|
'published': bool(row['published']),
|
||||||
@@ -466,6 +468,7 @@ def search_notes_fallback(
|
|||||||
'id': row['id'],
|
'id': row['id'],
|
||||||
'slug': row['slug'],
|
'slug': row['slug'],
|
||||||
'title': title,
|
'title': title,
|
||||||
|
'article_title': row['title'],
|
||||||
'snippet': generate_snippet(content, query),
|
'snippet': generate_snippet(content, query),
|
||||||
'relevance': 0.0, # No ranking in fallback mode
|
'relevance': 0.0, # No ranking in fallback mode
|
||||||
'published': bool(row['published']),
|
'published': bool(row['published']),
|
||||||
|
|||||||
@@ -288,6 +288,35 @@ def generate_timestamp_slug(
|
|||||||
return f"{base_slug}-{suffix}"
|
return f"{base_slug}-{suffix}"
|
||||||
|
|
||||||
|
|
||||||
|
TITLE_SLUG_LENGTH = 80
|
||||||
|
|
||||||
|
|
||||||
|
def generate_title_slug(title: str, existing_slugs: Set[str]) -> Optional[str]:
|
||||||
|
"""
|
||||||
|
A slug made from an article's title (v2.17.0)
|
||||||
|
|
||||||
|
"Why I Left Twitter" becomes 'why-i-left-twitter'; long titles are cut at
|
||||||
|
a word boundary, and a taken slug gets -2, -3, ...
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
The slug, or None when the title has nothing usable (e.g. only emoji),
|
||||||
|
so the caller falls back to a timestamp slug.
|
||||||
|
"""
|
||||||
|
slug = sanitize_slug(title or "")
|
||||||
|
if len(slug) > TITLE_SLUG_LENGTH:
|
||||||
|
cut = slug[:TITLE_SLUG_LENGTH + 1]
|
||||||
|
slug = cut.rsplit("-", 1)[0] if "-" in cut else slug[:TITLE_SLUG_LENGTH]
|
||||||
|
slug = slug.strip("-")
|
||||||
|
if not slug:
|
||||||
|
return None
|
||||||
|
if is_reserved_slug(slug):
|
||||||
|
slug = f"{slug}-article"
|
||||||
|
try:
|
||||||
|
return make_slug_unique_with_suffix(slug, existing_slugs)
|
||||||
|
except ValueError: # 99 articles with this title
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def validate_and_sanitize_custom_slug(custom_slug: str, existing_slugs: Set[str]) -> tuple[bool, Optional[str], Optional[str]]:
|
def validate_and_sanitize_custom_slug(custom_slug: str, existing_slugs: Set[str]) -> tuple[bool, Optional[str], Optional[str]]:
|
||||||
"""
|
"""
|
||||||
Validate and sanitize a custom slug from Micropub
|
Validate and sanitize a custom slug from Micropub
|
||||||
|
|||||||
@@ -1524,7 +1524,7 @@ def _reconcile(row, target: Target) -> tuple:
|
|||||||
site = current_app.config["SITE_URL"].rstrip("/")
|
site = current_app.config["SITE_URL"].rstrip("/")
|
||||||
post = Post(
|
post = Post(
|
||||||
note=note,
|
note=note,
|
||||||
permalink=f"{site}/note/{note.slug}",
|
permalink=note.url,
|
||||||
tags=[t["display_name"] for t in get_note_tags(note.id, entered_order=True)],
|
tags=[t["display_name"] for t in get_note_tags(note.id, entered_order=True)],
|
||||||
max_chars=target.max_chars,
|
max_chars=target.max_chars,
|
||||||
# Articles are posted as a teaser without images (v2.16.0)
|
# Articles are posted as a teaser without images (v2.16.0)
|
||||||
|
|||||||
@@ -716,6 +716,23 @@ def absolute_url_for(endpoint: str, **values) -> str:
|
|||||||
return current_app.config["SITE_URL"].rstrip("/") + url_for(endpoint, **values)
|
return current_app.config["SITE_URL"].rstrip("/") + url_for(endpoint, **values)
|
||||||
|
|
||||||
|
|
||||||
|
def post_path(slug: str, title: Optional[str] = None) -> str:
|
||||||
|
"""A post's URL path: /article/<slug> when it has a title, else /note/<slug> (v2.17.0)"""
|
||||||
|
return f"/{'article' if title else 'note'}/{slug}"
|
||||||
|
|
||||||
|
|
||||||
|
def post_url(slug: str, title: Optional[str] = None) -> str:
|
||||||
|
"""
|
||||||
|
A post's absolute URL (see post_path)
|
||||||
|
|
||||||
|
Built from SITE_URL without url_for, so it works outside a request:
|
||||||
|
crossposting and backfeed run in background workers (v2.17.0).
|
||||||
|
"""
|
||||||
|
from flask import current_app
|
||||||
|
|
||||||
|
return current_app.config["SITE_URL"].rstrip("/") + post_path(slug, title)
|
||||||
|
|
||||||
|
|
||||||
def iso_utc(value) -> str:
|
def iso_utc(value) -> str:
|
||||||
"""
|
"""
|
||||||
Format a timestamp as RFC 3339 UTC for dt-* and Micropub (v2.8.0)
|
Format a timestamp as RFC 3339 UTC for dt-* and Micropub (v2.8.0)
|
||||||
|
|||||||
+20
-1
@@ -8,7 +8,7 @@
|
|||||||
--font-reading: Charter, 'Bitstream Charter', 'Sitka Text', Cambria, 'Noto Serif', Georgia, serif;
|
--font-reading: Charter, 'Bitstream Charter', 'Sitka Text', Cambria, 'Noto Serif', Georgia, serif;
|
||||||
--font-mono: ui-monospace, 'SF Mono', Monaco, Consolas, 'Liberation Mono', monospace;
|
--font-mono: ui-monospace, 'SF Mono', Monaco, Consolas, 'Liberation Mono', monospace;
|
||||||
--spacing-xs: 0.25rem; --spacing-sm: 0.5rem; --spacing-md: 1rem; --spacing-lg: 2rem; --spacing-xl: 4rem;
|
--spacing-xs: 0.25rem; --spacing-sm: 0.5rem; --spacing-md: 1rem; --spacing-lg: 2rem; --spacing-xl: 4rem;
|
||||||
--max-width: 40rem; --border-radius: 6px;
|
--max-width: 48rem; --frame-width: 60rem; --border-radius: 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
@media (prefers-color-scheme: dark) {
|
||||||
@@ -40,6 +40,9 @@ pre code { padding: 0; background: none; }
|
|||||||
|
|
||||||
/* Page frame */
|
/* Page frame */
|
||||||
.site-header, main, .site-footer { width: 100%; max-width: var(--max-width); margin-left: auto; margin-right: auto; }
|
.site-header, main, .site-footer { width: 100%; max-width: var(--max-width); margin-left: auto; margin-right: auto; }
|
||||||
|
/* Header and footer share one width on every page, public and admin (v2.18.2);
|
||||||
|
only the content column (main) differs: 48rem to read, 60rem for admin tables. */
|
||||||
|
.site-header, .site-footer { max-width: var(--frame-width); }
|
||||||
main { flex: 1; margin-bottom: var(--spacing-xl); }
|
main { flex: 1; margin-bottom: var(--spacing-xl); }
|
||||||
|
|
||||||
.site-header {
|
.site-header {
|
||||||
@@ -91,6 +94,15 @@ main { flex: 1; margin-bottom: var(--spacing-xl); }
|
|||||||
.e-content blockquote { margin: 0 0 var(--spacing-md); padding-left: var(--spacing-md); border-left: 3px solid var(--color-border); color: var(--color-text-light); }
|
.e-content blockquote { margin: 0 0 var(--spacing-md); padding-left: var(--spacing-md); border-left: 3px solid var(--color-border); color: var(--color-text-light); }
|
||||||
.e-content ul, .e-content ol { margin: 0 0 var(--spacing-md) 1.25rem; }
|
.e-content ul, .e-content ol { margin: 0 0 var(--spacing-md) 1.25rem; }
|
||||||
.e-content img { max-width: 100%; height: auto; }
|
.e-content img { max-width: 100%; height: auto; }
|
||||||
|
/* Tables (v2.18.2): a card that fills the column, in the page's sans font at
|
||||||
|
the reading size; scrolls sideways when wider than the column. Words in
|
||||||
|
cells are never split (overflow-wrap: anywhere above is for long URLs in
|
||||||
|
prose; in a cell it squeezed columns to a few letters). */
|
||||||
|
.e-content .table-wrap { overflow-x: auto; margin: 0 0 var(--spacing-md); background: var(--color-bg-alt); border: 1px solid var(--color-border); border-radius: var(--border-radius); }
|
||||||
|
.e-content table { width: 100%; border-collapse: collapse; font-family: var(--font-body); font-size: 1.0625rem; line-height: 1.6; }
|
||||||
|
.e-content th, .e-content td { padding: 0.9rem 1.25rem; text-align: left; vertical-align: top; overflow-wrap: normal; }
|
||||||
|
.e-content th { font-weight: 600; white-space: nowrap; background: color-mix(in srgb, var(--color-text) 6%, var(--color-bg-alt)); }
|
||||||
|
.e-content td:first-child { font-weight: 600; }
|
||||||
.e-content h1, .e-content h2, .e-content h3 { font-family: var(--font-body); }
|
.e-content h1, .e-content h2, .e-content h3 { font-family: var(--font-body); }
|
||||||
.reaction { margin-bottom: var(--spacing-sm); font-size: 0.9375rem; color: var(--color-text-light); overflow-wrap: anywhere; }
|
.reaction { margin-bottom: var(--spacing-sm); font-size: 0.9375rem; color: var(--color-text-light); overflow-wrap: anywhere; }
|
||||||
.reaction-verb { font-weight: 600; margin-right: 0.25rem; }
|
.reaction-verb { font-weight: 600; margin-right: 0.25rem; }
|
||||||
@@ -465,6 +477,13 @@ small { display: block; margin-top: var(--spacing-xs); color: var(--color-text-l
|
|||||||
.badge-like { background: #FECACA; color: #991B1B; }
|
.badge-like { background: #FECACA; color: #991B1B; }
|
||||||
.badge-repost { background: #D1FAE5; color: #065F46; }
|
.badge-repost { background: #D1FAE5; color: #065F46; }
|
||||||
.badge-bookmark { background: #FEF3C7; color: #92400E; }
|
.badge-bookmark { background: #FEF3C7; color: #92400E; }
|
||||||
|
.badge-error { background: var(--color-error); color: #fff; }
|
||||||
|
|
||||||
|
/* Admin Log (v2.18.0) */
|
||||||
|
.log-table td { vertical-align: top; }
|
||||||
|
.log-table .button { white-space: nowrap; }
|
||||||
|
.log-error code { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 0.85rem; }
|
||||||
|
.backfeed-status { margin-bottom: var(--spacing-lg); }
|
||||||
.badge-mention { background: #E5E7EB; color: #374151; }
|
.badge-mention { background: #E5E7EB; color: #374151; }
|
||||||
|
|
||||||
.status-badge {
|
.status-badge {
|
||||||
|
|||||||
@@ -8,7 +8,10 @@
|
|||||||
<nav class="admin-nav">
|
<nav class="admin-nav">
|
||||||
<a href="{{ url_for('admin.dashboard') }}">Dashboard</a>
|
<a href="{{ url_for('admin.dashboard') }}">Dashboard</a>
|
||||||
<a href="{{ url_for('admin.new_note_form') }}">New Note</a>
|
<a href="{{ url_for('admin.new_note_form') }}">New Note</a>
|
||||||
|
{% if config.WEBMENTION_ENABLED %}<a href="{{ url_for('admin.webmentions') }}">Webmentions</a>{% endif %}
|
||||||
|
<a href="{{ url_for('admin.error_log') }}">Log{% if error_count %} <span class="badge badge-error">{{ error_count }}</span>{% endif %}</a>
|
||||||
<a href="{{ url_for('admin.tokens') }}">Connected Apps</a>
|
<a href="{{ url_for('admin.tokens') }}">Connected Apps</a>
|
||||||
|
<a href="{{ url_for('admin.settings') }}">Settings</a>
|
||||||
<form action="{{ url_for('auth.logout') }}" method="POST" class="logout-form"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
<form action="{{ url_for('auth.logout') }}" method="POST" class="logout-form"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||||
<button type="submit" class="button button-secondary">Logout</button>
|
<button type="submit" class="button button-secondary">Logout</button>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -67,7 +67,7 @@
|
|||||||
</td>
|
</td>
|
||||||
<td class="note-actions">
|
<td class="note-actions">
|
||||||
{% if note.published %}
|
{% if note.published %}
|
||||||
<a href="{{ url_for('public.note', slug=note.slug) }}" class="button button-small" target="_blank">
|
<a href="{{ note.url }}" class="button button-small" target="_blank">
|
||||||
View
|
View
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
{% extends "admin/base.html" %}
|
||||||
|
|
||||||
|
{% block title %}Log - StarPunk Admin{% endblock %}
|
||||||
|
|
||||||
|
{% block admin_content %}
|
||||||
|
<div class="log-admin">
|
||||||
|
<h2>Log</h2>
|
||||||
|
<p class="text-muted">What is failing right now. An entry goes away once the next attempt succeeds.</p>
|
||||||
|
|
||||||
|
{% if entries %}
|
||||||
|
<div class="table-scroll">
|
||||||
|
<table class="note-table log-table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>When (UTC)</th>
|
||||||
|
<th>What</th>
|
||||||
|
<th>Post</th>
|
||||||
|
<th>Error</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for e in entries %}
|
||||||
|
<tr>
|
||||||
|
<td class="note-date">{{ e.when or '' }}</td>
|
||||||
|
<td>
|
||||||
|
{{ e.area }}
|
||||||
|
{% if e.detail %}<br><small class="note-slug">{% if e.detail.startswith('http') %}<a href="{{ e.detail.split(' ')[0] }}" target="_blank" rel="noopener">{{ e.detail|truncate(60) }}</a>{% else %}{{ e.detail|truncate(80) }}{% endif %}</small>{% endif %}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{% if e.note %}
|
||||||
|
<a href="{{ url_for('admin.edit_note_form', note_id=e.note.id) }}">{{ (e.note.title or e.note.content or e.note.slug)|truncate(60) }}</a>
|
||||||
|
{% if e.note.published %}<br><small><a href="{{ e.note.url }}" target="_blank">View</a></small>{% endif %}
|
||||||
|
{% else %}
|
||||||
|
<span class="text-muted">Site-wide</span>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
<td class="log-error"><code>{{ e.error }}</code></td>
|
||||||
|
<td>
|
||||||
|
{% if e.action %}
|
||||||
|
<form method="POST" action="{{ url_for(e.action[0], syndication_id=e.action[1]) }}"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||||
|
<button type="submit" class="button button-small">{{ e.action[2] }}</button>
|
||||||
|
</form>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
<div class="empty-state">
|
||||||
|
<p>No errors. Crossposts, response checks, webmentions, WebSub and notifications are all working.</p>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
{% extends "admin/base.html" %}
|
||||||
|
|
||||||
|
{% block title %}Settings - StarPunk Admin{% endblock %}
|
||||||
|
|
||||||
|
{% block admin_content %}
|
||||||
|
<div class="settings-admin">
|
||||||
|
<h2>Settings</h2>
|
||||||
|
|
||||||
|
{# Notifications (v2.14.0, ADR-074; moved here in v2.18.0) #}
|
||||||
|
<section class="notify-status">
|
||||||
|
<h3>Notifications</h3>
|
||||||
|
{% if notify.enabled %}
|
||||||
|
<p>Sending {{ notify.events|join(', ') }} to {{ notify.services|join(', ') }} at {{ notify.priority }} priority.</p>
|
||||||
|
{% if notify.last_error %}<p class="flash flash-error">Last send failed: {{ notify.last_error }}</p>{% endif %}
|
||||||
|
<form method="POST" action="{{ url_for('admin.notifications_test') }}"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||||
|
<button type="submit" class="button">Send test notification</button>
|
||||||
|
</form>
|
||||||
|
{% else %}
|
||||||
|
<p>Off. Set <code>NOTIFY_URLS</code> to one or more Apprise URLs to be notified of new responses.</p>
|
||||||
|
{% endif %}
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
@@ -6,35 +6,10 @@
|
|||||||
<div class="webmentions-admin">
|
<div class="webmentions-admin">
|
||||||
<h2>Webmentions</h2>
|
<h2>Webmentions</h2>
|
||||||
|
|
||||||
<div class="dashboard-actions">
|
|
||||||
<a href="{{ url_for('admin.dashboard') }}" class="button">
|
|
||||||
Back to Dashboard
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{# Notifications (v2.14.0, ADR-074) #}
|
|
||||||
{% if notify %}
|
|
||||||
<section class="notify-status">
|
|
||||||
<h3>Notifications</h3>
|
|
||||||
{% if notify.enabled %}
|
|
||||||
<p>Sending {{ notify.events|join(', ') }} to {{ notify.services|join(', ') }} at {{ notify.priority }} priority.</p>
|
|
||||||
{% if notify.last_error %}<p class="flash flash-error">Last send failed: {{ notify.last_error }}</p>{% endif %}
|
|
||||||
<form method="POST" action="{{ url_for('admin.notifications_test') }}"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
|
||||||
<button type="submit" class="button">Send test notification</button>
|
|
||||||
</form>
|
|
||||||
{% else %}
|
|
||||||
<p>Off. Set <code>NOTIFY_URLS</code> to one or more Apprise URLs to be notified of new responses.</p>
|
|
||||||
{% endif %}
|
|
||||||
</section>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{# Backfeed (v2.13.0, ADR-073) #}
|
{# Backfeed (v2.13.0, ADR-073) #}
|
||||||
{% if backfeed and backfeed.enabled %}
|
{% if backfeed and backfeed.enabled %}
|
||||||
<section class="backfeed-status">
|
<section class="backfeed-status">
|
||||||
<h3>Backfeed</h3>
|
<h3>Backfeed</h3>
|
||||||
{% for silo, message in backfeed.denied.items() %}
|
|
||||||
<p class="flash flash-error">{{ silo }}: {{ message }}</p>
|
|
||||||
{% endfor %}
|
|
||||||
{% if backfeed.remaining %}
|
{% if backfeed.remaining %}
|
||||||
<p>Backfill started {{ backfeed.started }} UTC: {{ backfeed.remaining }} crosspost(s) left to check.</p>
|
<p>Backfill started {{ backfeed.started }} UTC: {{ backfeed.remaining }} crosspost(s) left to check.</p>
|
||||||
{% elif backfeed.finished %}
|
{% elif backfeed.finished %}
|
||||||
@@ -42,7 +17,7 @@
|
|||||||
{% else %}
|
{% else %}
|
||||||
<p>No backfill has been run. It checks every crosspost once for responses, however old the note.</p>
|
<p>No backfill has been run. It checks every crosspost once for responses, however old the note.</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if backfeed.errors %}<p>{{ backfeed.errors }} crosspost(s) had an error at their last check (see each note's edit page).</p>{% endif %}
|
{% if backfeed.errors or backfeed.denied %}<p><a href="{{ url_for('admin.error_log') }}">Response checks have errors: see the Log.</a></p>{% endif %}
|
||||||
<form method="POST" action="{{ url_for('admin.backfeed_backfill') }}"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
<form method="POST" action="{{ url_for('admin.backfeed_backfill') }}"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||||
<button type="submit" class="button"{% if backfeed.remaining %} disabled{% endif %}>Backfill responses</button>
|
<button type="submit" class="button"{% if backfeed.remaining %} disabled{% endif %}>Backfill responses</button>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
+2
-2
@@ -54,7 +54,7 @@
|
|||||||
|
|
||||||
<footer class="note-meta">
|
<footer class="note-meta">
|
||||||
{# u-url and u-uid same for notes (per Q23) #}
|
{# u-url and u-uid same for notes (per Q23) #}
|
||||||
<a class="u-url u-uid" href="{{ absolute_url_for('public.note', slug=note.slug) }}"><time class="dt-published" datetime="{{ note.created_at|iso_utc }}">{{ note.created_at.strftime('%B %-d, %Y · %-I:%M %p') }}</time></a>
|
<a class="u-url u-uid" href="{{ note.url }}"><time class="dt-published" datetime="{{ note.created_at|iso_utc }}">{{ note.created_at.strftime('%B %-d, %Y · %-I:%M %p') }}</time></a>
|
||||||
{% if note.updated_at and note.updated_at != note.created_at %}
|
{% if note.updated_at and note.updated_at != note.created_at %}
|
||||||
<span class="updated">Updated <time class="dt-updated" datetime="{{ note.updated_at|iso_utc }}">{{ note.updated_at.strftime('%b %-d, %Y') }}</time></span>
|
<span class="updated">Updated <time class="dt-updated" datetime="{{ note.updated_at|iso_utc }}">{{ note.updated_at.strftime('%b %-d, %Y') }}</time></span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@@ -79,7 +79,7 @@
|
|||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
<div id="responses"></div>
|
<div id="responses"></div>
|
||||||
{{ responses.reactions(likes, reposts, replies, bookmarks, syndications, absolute_url_for('public.note', slug=note.slug), quotes) }}
|
{{ responses.reactions(likes, reposts, replies, bookmarks, syndications, note.url, quotes) }}
|
||||||
|
|
||||||
<nav class="note-nav">
|
<nav class="note-nav">
|
||||||
<a href="/">← All notes</a>
|
<a href="/">← All notes</a>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<article class="h-entry note-preview">
|
<article class="h-entry note-preview">
|
||||||
{# Titled notes are articles (ADR-076) #}
|
{# Titled notes are articles (ADR-076) #}
|
||||||
{% if note.title %}
|
{% if note.title %}
|
||||||
<h2 class="p-name"><a href="{{ absolute_url_for('public.note', slug=note.slug) }}">{{ note.title }}</a></h2>
|
<h2 class="p-name"><a href="{{ note.url }}">{{ note.title }}</a></h2>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if note.in_reply_to %}
|
{% if note.in_reply_to %}
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
<p>{{ summary }}</p>
|
<p>{{ summary }}</p>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<p class="read-more"><a href="{{ absolute_url_for('public.note', slug=note.slug) }}">Read more →</a></p>
|
<p class="read-more"><a href="{{ note.url }}">Read more →</a></p>
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ display_media(note.media, note.excerpt|truncate(150)) }}
|
{{ display_media(note.media, note.excerpt|truncate(150)) }}
|
||||||
{# Always present, even empty: without it a text-free photo post gets an implied name (mf2) #}
|
{# Always present, even empty: without it a text-free photo post gets an implied name (mf2) #}
|
||||||
@@ -35,13 +35,13 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<footer class="note-meta">
|
<footer class="note-meta">
|
||||||
<a class="u-url u-uid" href="{{ absolute_url_for('public.note', slug=note.slug) }}"><time class="dt-published" datetime="{{ note.created_at|iso_utc }}">{{ note.created_at.strftime('%b %-d, %Y') }}</time></a>
|
<a class="u-url u-uid" href="{{ note.url }}"><time class="dt-published" datetime="{{ note.created_at|iso_utc }}">{{ note.created_at.strftime('%b %-d, %Y') }}</time></a>
|
||||||
{% if note.tags %}
|
{% if note.tags %}
|
||||||
<span class="note-tags">
|
<span class="note-tags">
|
||||||
{% for tag in note.tags %}<a class="p-category" rel="tag" href="{{ url_for('public.tag', tag=tag.name) }}">{{ tag.display_name }}</a>{% endfor %}
|
{% for tag in note.tags %}<a class="p-category" rel="tag" href="{{ url_for('public.tag', tag=tag.name) }}">{{ tag.display_name }}</a>{% endfor %}
|
||||||
</span>
|
</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{{ list_counts(note.response_counts if note.response_counts is defined else None, absolute_url_for('public.note', slug=note.slug)) }}
|
{{ list_counts(note.response_counts if note.response_counts is defined else None, note.url) }}
|
||||||
{% if author %}
|
{% if author %}
|
||||||
{# Single-author site: keep the h-card for parsers, hide it from readers #}
|
{# Single-author site: keep the h-card for parsers, hide it from readers #}
|
||||||
<span class="p-author h-card visually-hidden"><a class="p-name u-url" href="{{ author.url or author.me }}">{{ author.name or author.url or author.me }}</a></span>
|
<span class="p-author h-card visually-hidden"><a class="p-name u-url" href="{{ author.url or author.me }}">{{ author.name or author.url or author.me }}</a></span>
|
||||||
|
|||||||
@@ -0,0 +1,119 @@
|
|||||||
|
"""Admin Log and Settings pages (v2.18.0)"""
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from starpunk import backfeed, create_app, error_log
|
||||||
|
from starpunk.auth import create_session
|
||||||
|
from starpunk.database import get_db
|
||||||
|
from starpunk.notes import create_note
|
||||||
|
|
||||||
|
SITE = "https://blog.example.com"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def app(tmp_path):
|
||||||
|
app = create_app({
|
||||||
|
"TESTING": True, "SITE_URL": SITE, "ADMIN_ME": "https://example.com",
|
||||||
|
"DATABASE_PATH": tmp_path / "starpunk.db", "DATA_PATH": tmp_path,
|
||||||
|
"NOTES_PATH": tmp_path / "notes", "SESSION_SECRET": "test", "CSRF_ENABLED": False,
|
||||||
|
"BACKGROUND_WORKERS_ENABLED": False, "WEBMENTION_ENABLED": True,
|
||||||
|
})
|
||||||
|
backfeed.denied.clear()
|
||||||
|
yield app
|
||||||
|
backfeed.denied.clear()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def browser(app):
|
||||||
|
with app.test_request_context():
|
||||||
|
token = create_session("https://example.com")
|
||||||
|
client = app.test_client()
|
||||||
|
client.set_cookie("starpunk_session", token)
|
||||||
|
return client
|
||||||
|
|
||||||
|
|
||||||
|
def _failures(app):
|
||||||
|
"""One of each kind of error, on two notes"""
|
||||||
|
with app.app_context():
|
||||||
|
broken = create_note(content="A crosspost that broke", published=True)
|
||||||
|
reply = create_note(content="Replying", published=True)
|
||||||
|
db = get_db(app)
|
||||||
|
db.execute("UPDATE notes SET in_reply_to = 'https://gone.example/post' WHERE id = ?", (reply.id,))
|
||||||
|
db.execute("INSERT INTO syndications (note_id, target, state, last_error, updated_at) "
|
||||||
|
"VALUES (?, 'bluesky', 'failed', 'HTTP 400: post too long', '2026-11-12 10:00:00')",
|
||||||
|
(broken.id,))
|
||||||
|
db.execute("INSERT INTO syndications (note_id, target, state, remote_url, backfeed_error, "
|
||||||
|
"backfeed_checked_at) VALUES (?, 'gotosocial', 'synced', 'https://social.example/1', "
|
||||||
|
"'HTTP 404 from GoToSocial', '2026-11-12 11:00:00')", (broken.id,))
|
||||||
|
db.execute("INSERT INTO webmention_queue (source_url, target_url, source_note_id, status, last_error) "
|
||||||
|
"VALUES (?, 'https://other.example/a', ?, 'failed', 'Endpoint returned 500')",
|
||||||
|
(f"{SITE}/note/{reply.slug}", reply.id))
|
||||||
|
db.execute("INSERT INTO reply_contexts (url, fetch_status, fetch_error) "
|
||||||
|
"VALUES ('https://gone.example/post', 'error', 'HTTP 410 Gone')")
|
||||||
|
db.execute("INSERT INTO syndications (note_id, target, state, last_error) "
|
||||||
|
"VALUES (?, 'threads', 'synced', 'old error, since fixed')", (reply.id,))
|
||||||
|
db.commit()
|
||||||
|
return broken, reply
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_lists_each_error_with_its_post(app, browser):
|
||||||
|
broken, reply = _failures(app)
|
||||||
|
backfeed.denied["threads"] = "Needs a Threads token with threads_manage_replies"
|
||||||
|
|
||||||
|
page = browser.get("/admin/log").get_data(as_text=True)
|
||||||
|
for text in ("Crosspost to Bluesky", "HTTP 400: post too long", "Retry",
|
||||||
|
"Response check on GoToSocial", "HTTP 404 from GoToSocial", "Check now",
|
||||||
|
"Webmention sent", "https://other.example/a", "Endpoint returned 500",
|
||||||
|
"Reply context fetch", "HTTP 410 Gone",
|
||||||
|
"Response checks on Threads", "Needs a Threads token", "Site-wide"):
|
||||||
|
assert text in page, text
|
||||||
|
assert f"/admin/edit/{broken.id}" in page and f"/admin/edit/{reply.id}" in page
|
||||||
|
assert "old error, since fixed" not in page, "synced crossposts aren't errors"
|
||||||
|
assert 'class="badge badge-error">5<' in page
|
||||||
|
|
||||||
|
with app.app_context():
|
||||||
|
assert error_log.count() == 5
|
||||||
|
areas = [e["area"] for e in error_log.entries()]
|
||||||
|
assert areas[0] == "Response checks on Threads", "site-wide problems first"
|
||||||
|
assert areas.index("Response check on GoToSocial") < areas.index("Crosspost to Bluesky"), "newest first"
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_retry_clears_the_crosspost_error(app, browser):
|
||||||
|
broken, _ = _failures(app)
|
||||||
|
with app.app_context():
|
||||||
|
sid = get_db(app).execute("SELECT id FROM syndications WHERE target = 'bluesky'").fetchone()[0]
|
||||||
|
browser.post(f"/admin/syndication/{sid}/retry")
|
||||||
|
assert "HTTP 400: post too long" not in browser.get("/admin/log").get_data(as_text=True)
|
||||||
|
|
||||||
|
|
||||||
|
def test_empty_log_and_no_badge(browser):
|
||||||
|
page = browser.get("/admin/log").get_data(as_text=True)
|
||||||
|
assert "No errors." in page and "badge-error" not in page
|
||||||
|
|
||||||
|
|
||||||
|
def test_notification_error_is_logged(app, browser):
|
||||||
|
with app.app_context():
|
||||||
|
get_db(app).execute("INSERT INTO site_state (key, value) VALUES "
|
||||||
|
"('notify_last_error', '2026-11-12 09:00:00 UTC gotify: 401 Unauthorized')")
|
||||||
|
get_db(app).commit()
|
||||||
|
page = browser.get("/admin/log").get_data(as_text=True)
|
||||||
|
assert "Notifications" in page and "gotify: 401 Unauthorized" in page and "2026-11-12 09:00:00" in page
|
||||||
|
|
||||||
|
|
||||||
|
def test_webmentions_page_is_decluttered(browser):
|
||||||
|
page = browser.get("/admin/webmentions").get_data(as_text=True)
|
||||||
|
assert "Back to Dashboard" not in page
|
||||||
|
assert "Send test notification" not in page and "<h3>Notifications</h3>" not in page
|
||||||
|
|
||||||
|
|
||||||
|
def test_nav_and_settings_page(browser):
|
||||||
|
page = browser.get("/admin/settings").get_data(as_text=True)
|
||||||
|
assert "<h3>Notifications</h3>" in page and "NOTIFY_URLS" in page
|
||||||
|
for link in ("/admin/webmentions", "/admin/log", "/admin/settings", "/admin/tokens"):
|
||||||
|
assert f'href="{link}"' in page, link
|
||||||
|
|
||||||
|
|
||||||
|
def test_pages_require_login(app):
|
||||||
|
client = app.test_client()
|
||||||
|
for path in ("/admin/log", "/admin/settings"):
|
||||||
|
assert client.get(path).status_code == 302
|
||||||
+85
-5
@@ -38,7 +38,7 @@ class TestFeeds:
|
|||||||
def test_rss_title_only_for_articles(self, app, client):
|
def test_rss_title_only_for_articles(self, app, client):
|
||||||
article, note = make_both(app)
|
article, note = make_both(app)
|
||||||
items = {i.find("link").text: i for i in ET.fromstring(client.get("/feed.rss").data).iter("item")}
|
items = {i.find("link").text: i for i in ET.fromstring(client.get("/feed.rss").data).iter("item")}
|
||||||
a, n = items[f"{SITE}/note/{article.slug}"], items[f"{SITE}/note/{note.slug}"]
|
a, n = items[f"{SITE}/article/{article.slug}"], items[f"{SITE}/note/{note.slug}"]
|
||||||
assert a.find("title").text == "An Article"
|
assert a.find("title").text == "An Article"
|
||||||
assert "An Article" not in a.find("description").text # not repeated in the body
|
assert "An Article" not in a.find("description").text # not repeated in the body
|
||||||
assert n.find("title") is None
|
assert n.find("title") is None
|
||||||
@@ -48,7 +48,7 @@ class TestFeeds:
|
|||||||
article, note = make_both(app)
|
article, note = make_both(app)
|
||||||
entries = {e.find("a:id", ATOM).text: e
|
entries = {e.find("a:id", ATOM).text: e
|
||||||
for e in ET.fromstring(client.get("/feed.atom").data).findall("a:entry", ATOM)}
|
for e in ET.fromstring(client.get("/feed.atom").data).findall("a:entry", ATOM)}
|
||||||
a, n = entries[f"{SITE}/note/{article.slug}"], entries[f"{SITE}/note/{note.slug}"]
|
a, n = entries[f"{SITE}/article/{article.slug}"], entries[f"{SITE}/note/{note.slug}"]
|
||||||
assert a.find("a:title", ATOM).text == "An Article"
|
assert a.find("a:title", ATOM).text == "An Article"
|
||||||
assert a.find("a:summary", ATOM).text == "The gist."
|
assert a.find("a:summary", ATOM).text == "The gist."
|
||||||
assert "An Article" not in a.find("a:content", ATOM).text
|
assert "An Article" not in a.find("a:content", ATOM).text
|
||||||
@@ -58,7 +58,7 @@ class TestFeeds:
|
|||||||
def test_json_feed(self, app, client):
|
def test_json_feed(self, app, client):
|
||||||
article, note = make_both(app)
|
article, note = make_both(app)
|
||||||
items = {i["url"]: i for i in json.loads(client.get("/feed.json").data)["items"]}
|
items = {i["url"]: i for i in json.loads(client.get("/feed.json").data)["items"]}
|
||||||
a, n = items[f"{SITE}/note/{article.slug}"], items[f"{SITE}/note/{note.slug}"]
|
a, n = items[f"{SITE}/article/{article.slug}"], items[f"{SITE}/note/{note.slug}"]
|
||||||
assert (a["title"], a["summary"]) == ("An Article", "The gist.")
|
assert (a["title"], a["summary"]) == ("An Article", "The gist.")
|
||||||
assert "An Article" not in a["content_html"]
|
assert "An Article" not in a["content_html"]
|
||||||
assert "title" not in n and "summary" not in n
|
assert "title" not in n and "summary" not in n
|
||||||
@@ -68,8 +68,8 @@ class TestFeeds:
|
|||||||
class TestPages:
|
class TestPages:
|
||||||
def test_article_page(self, app, client):
|
def test_article_page(self, app, client):
|
||||||
article, _ = make_both(app)
|
article, _ = make_both(app)
|
||||||
(entry,) = [i for i in mf2py.parse(doc=client.get(f"/note/{article.slug}").data.decode(),
|
(entry,) = [i for i in mf2py.parse(doc=client.get(f"/article/{article.slug}").data.decode(),
|
||||||
url=f"{SITE}/note/{article.slug}")["items"]
|
url=f"{SITE}/article/{article.slug}")["items"]
|
||||||
if "h-entry" in i["type"]]
|
if "h-entry" in i["type"]]
|
||||||
props = entry["properties"]
|
props = entry["properties"]
|
||||||
assert props["name"] == ["An Article"]
|
assert props["name"] == ["An Article"]
|
||||||
@@ -193,3 +193,83 @@ class TestInlineImages:
|
|||||||
"replace": {"content": [""]}}, headers=h)
|
"replace": {"content": [""]}}, headers=h)
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
assert f"]({SITE}/media/" in get_note(slug=url.rsplit("/", 1)[1]).content
|
assert f"]({SITE}/media/" in get_note(slug=url.rsplit("/", 1)[1]).content
|
||||||
|
|
||||||
|
|
||||||
|
class TestArticleUrls:
|
||||||
|
"""Articles live at /article/<title-slug>, notes at /note/<slug> (v2.17.0)"""
|
||||||
|
|
||||||
|
def test_micropub_article_gets_article_url_from_title(self, app, client, h):
|
||||||
|
url = micropub(client, h, name=["Why I Left Twitter!"], content=["Long story."])
|
||||||
|
assert url == f"{SITE}/article/why-i-left-twitter"
|
||||||
|
assert source(client, h, url)["properties"]["url"] == [url]
|
||||||
|
assert client.get("/article/why-i-left-twitter").status_code == 200
|
||||||
|
|
||||||
|
def test_note_keeps_note_url_and_timestamp_slug(self, app, client, h):
|
||||||
|
url = micropub(client, h, content=["Just a note"])
|
||||||
|
assert url.startswith(f"{SITE}/note/") and url.rsplit("/", 1)[1][:8].isdigit()
|
||||||
|
|
||||||
|
def test_wrong_prefix_redirects(self, app, client, h):
|
||||||
|
article = micropub(client, h, name=["Moved"], content=["Body"])
|
||||||
|
note = micropub(client, h, content=["Plain"])
|
||||||
|
slug, note_slug = article.rsplit("/", 1)[1], note.rsplit("/", 1)[1]
|
||||||
|
response = client.get(f"/note/{slug}")
|
||||||
|
assert (response.status_code, response.location) == (301, f"/article/{slug}")
|
||||||
|
response = client.get(f"/article/{note_slug}")
|
||||||
|
assert (response.status_code, response.location) == (301, f"/note/{note_slug}")
|
||||||
|
assert client.get("/article/no-such-post").status_code == 404
|
||||||
|
|
||||||
|
def test_micropub_accepts_either_url(self, app, client, h):
|
||||||
|
url = micropub(client, h, name=["Either"], content=["Body"])
|
||||||
|
old_style = url.replace("/article/", "/note/")
|
||||||
|
response = client.post("/micropub", json={"action": "update", "url": old_style,
|
||||||
|
"replace": {"summary": ["S"]}}, headers=h)
|
||||||
|
assert response.status_code == 204
|
||||||
|
assert source(client, h, url)["properties"]["summary"] == ["S"]
|
||||||
|
|
||||||
|
def test_title_slugs(self, app):
|
||||||
|
with app.test_request_context():
|
||||||
|
def slug(title, **kw):
|
||||||
|
return create_note(content="Body", title=title, published=True, **kw).slug
|
||||||
|
|
||||||
|
assert slug("Café Culture") == "cafe-culture"
|
||||||
|
assert slug("Café Culture") == "cafe-culture-2"
|
||||||
|
assert slug("Search") == "search-article" # reserved
|
||||||
|
assert slug("Mine", custom_slug="chosen") == "chosen" # mp-slug wins
|
||||||
|
assert slug("🎉🎉").isdigit() # nothing usable: timestamp
|
||||||
|
long = slug("word " * 40)
|
||||||
|
assert len(long) <= 80 and long.endswith("word") and "--" not in long
|
||||||
|
|
||||||
|
def test_update_that_adds_or_removes_title_returns_new_url(self, app, client, h):
|
||||||
|
note = micropub(client, h, content=["Starts as a note"])
|
||||||
|
slug = note.rsplit("/", 1)[1]
|
||||||
|
response = client.post("/micropub", json={"action": "update", "url": note,
|
||||||
|
"replace": {"name": ["Now an Article"]}}, headers=h)
|
||||||
|
assert (response.status_code, response.headers["Location"]) == (201, f"{SITE}/article/{slug}")
|
||||||
|
response = client.post("/micropub", json={"action": "update", "url": f"{SITE}/article/{slug}",
|
||||||
|
"replace": {"content": ["Edited"]}}, headers=h)
|
||||||
|
assert response.status_code == 204 # URL unchanged
|
||||||
|
response = client.post("/micropub", json={"action": "update", "url": f"{SITE}/article/{slug}",
|
||||||
|
"delete": ["name"]}, headers=h)
|
||||||
|
assert (response.status_code, response.headers["Location"]) == (201, f"{SITE}/note/{slug}")
|
||||||
|
|
||||||
|
def test_deleted_article_is_gone(self, app, client, h):
|
||||||
|
url = micropub(client, h, name=["Short-lived"], content=["Body"])
|
||||||
|
assert client.post("/micropub", data={"action": "delete", "url": url}, headers=h).status_code == 204
|
||||||
|
assert client.get("/article/short-lived").status_code == 410
|
||||||
|
|
||||||
|
def test_webmention_target_and_links(self, app, client):
|
||||||
|
article, note = make_both(app)
|
||||||
|
from starpunk.routes.webmention import resolve_target_note
|
||||||
|
with app.test_request_context():
|
||||||
|
assert resolve_target_note(f"{SITE}/article/{article.slug}") == article.id
|
||||||
|
assert resolve_target_note(f"{SITE}/note/{article.slug}") == article.id
|
||||||
|
assert resolve_target_note(f"{SITE}/article/{article.slug}/x") is None
|
||||||
|
html = client.get("/").data.decode()
|
||||||
|
assert f'href="{SITE}/article/{article.slug}"' in html
|
||||||
|
assert f'href="{SITE}/note/{note.slug}"' in html
|
||||||
|
assert f"/note/{article.slug}" not in html
|
||||||
|
|
||||||
|
def test_search_links_to_article(self, app, client):
|
||||||
|
article, _ = make_both(app)
|
||||||
|
results = client.get("/api/search?q=body").get_json()["results"]
|
||||||
|
assert [r["url"] for r in results if r["slug"] == article.slug] == [f"/article/{article.slug}"]
|
||||||
@@ -543,7 +543,8 @@ def test_admin_backfill_and_check_now(app, client):
|
|||||||
assert s["backfeed_next_at"]
|
assert s["backfeed_next_at"]
|
||||||
|
|
||||||
backfeed.denied["gotosocial"] = "Needs a GoToSocial token with read:statuses"
|
backfeed.denied["gotosocial"] = "Needs a GoToSocial token with read:statuses"
|
||||||
assert "Needs a GoToSocial token" in browser.get("/admin/webmentions?origin=gotosocial").get_data(as_text=True)
|
assert "Needs a GoToSocial token" in browser.get("/admin/log").get_data(as_text=True)
|
||||||
|
assert "Response checks have errors" in browser.get("/admin/webmentions").get_data(as_text=True)
|
||||||
|
|
||||||
|
|
||||||
def test_threads_avatar_kept_while_its_copy_exists(app, client, web):
|
def test_threads_avatar_kept_while_its_copy_exists(app, client, web):
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
|
||||||
|
|
||||||
|
def test_tables_get_a_scroll_wrapper():
|
||||||
|
"""v2.18.2: tables are wrapped so they can fill the column and scroll sideways"""
|
||||||
|
from starpunk.models import render_markdown
|
||||||
|
|
||||||
|
html = render_markdown("| Color | Why |\n|---|---|\n| Black | Removal |\n\nAfter")
|
||||||
|
assert html.startswith('<div class="table-wrap"><table>') and "</table></div>" in html
|
||||||
|
assert "<p>After</p>" in html
|
||||||
@@ -69,9 +69,9 @@ class TestNoteHEntry:
|
|||||||
published=True
|
published=True
|
||||||
)
|
)
|
||||||
|
|
||||||
response = client.get('/note/note-with-title')
|
response = client.get('/article/note-with-title')
|
||||||
assert response.status_code == 200, f"Failed to get note: {response.status_code}"
|
assert response.status_code == 200, f"Failed to get note: {response.status_code}"
|
||||||
parsed = mf2py.parse(doc=response.data.decode(), url='http://localhost/note/note-with-title')
|
parsed = mf2py.parse(doc=response.data.decode(), url='http://localhost/article/note-with-title')
|
||||||
|
|
||||||
entries = [item for item in parsed['items'] if 'h-entry' in item.get('type', [])]
|
entries = [item for item in parsed['items'] if 'h-entry' in item.get('type', [])]
|
||||||
assert len(entries) > 0, "No h-entry found in parsed HTML"
|
assert len(entries) > 0, "No h-entry found in parsed HTML"
|
||||||
|
|||||||
@@ -209,10 +209,10 @@ def test_admin_status_and_test_button(app, sent):
|
|||||||
token = create_session("https://example.com")
|
token = create_session("https://example.com")
|
||||||
browser = app.test_client()
|
browser = app.test_client()
|
||||||
browser.set_cookie("starpunk_session", token)
|
browser.set_cookie("starpunk_session", token)
|
||||||
page = browser.get("/admin/webmentions").get_data(as_text=True)
|
page = browser.get("/admin/settings").get_data(as_text=True)
|
||||||
assert "Sending like, mention, problems, reply to gotifys, ntfys at high priority" in page
|
assert "Sending like, mention, problems, reply to gotifys, ntfys at high priority" in page
|
||||||
page = browser.post("/admin/notifications/test", follow_redirects=True).get_data(as_text=True)
|
page = browser.post("/admin/notifications/test", follow_redirects=True).get_data(as_text=True)
|
||||||
assert "Test notification sent" in page and sent[-1]["title"] == "StarPunk test notification"
|
assert "Test notification sent" in page and "<h2>Settings</h2>" in page and sent[-1]["title"] == "StarPunk test notification"
|
||||||
|
|
||||||
|
|
||||||
# --- Real Apprise -------------------------------------------------------------------------------------
|
# --- Real Apprise -------------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ class TestLifecycle:
|
|||||||
select_targets(note.id, ["bluesky"])
|
select_targets(note.id, ["bluesky"])
|
||||||
process_due()
|
process_due()
|
||||||
record = only_record(pds)
|
record = only_record(pds)
|
||||||
permalink = f"https://blog.example.com/note/{note.slug}"
|
permalink = f"https://blog.example.com/article/{note.slug}"
|
||||||
assert record["text"] == f"My Article\n\nThe gist.\n\n{permalink}"
|
assert record["text"] == f"My Article\n\nThe gist.\n\n{permalink}"
|
||||||
assert record["embed"]["external"] == {
|
assert record["embed"]["external"] == {
|
||||||
"uri": permalink, "title": "My Article", "description": "The gist."}
|
"uri": permalink, "title": "My Article", "description": "The gist."}
|
||||||
|
|||||||
Reference in new issue
Block a user