Compare commits

...
2 Commits
Author SHA1 Message Date
PhilandClaude Opus 5.5 d16463ef8a Merge branch 'fix/v2.6.4-tag-order' for v2.6.4 release
Build Container / build (push) Successful in 7s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 08:59:19 -07:00
PhilandClaude Opus 5.5 4b56f7cd4b fix: Tags keep the order they were entered in (v2.6.4)
add_tags_to_note() rewrites note_tags in entry order on every save, so
note_tags.id already records it; get_note_tags(entered_order=True) reads
it back. Crossposts (Threads topic, which hashtags fit on Bluesky), the
editor and Micropub q=source/update use it, so saving no longer
reorders tags alphabetically. Public pages stay alphabetical.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 08:59:18 -07:00
8 changed files with 118 additions and 15 deletions

No files matched your search

+7
View File
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
## [2.6.4] - 2026-11-01
### Fixed
- Tags keep the order you entered them in. The first tag is the note's main tag: it's the Threads topic, and Bluesky keeps the first tags when space runs out. Before, both used the alphabetically first tag. Public pages still list tags alphabetically
- Opening a note in the editor or updating it via Micropub reordered its tags alphabetically on save; the editor and Micropub `q=source` now show, and keep, the entered order
## [2.6.3] - 2026-11-01
### Changed
+2 -2
View File
@@ -464,5 +464,5 @@ def create_app(config=None):
# Package version (Semantic Versioning 2.0.0)
# See docs/standards/versioning-strategy.md for details
__version__ = "2.6.3"
__version_info__ = (2, 6, 3)
__version__ = "2.6.4"
__version_info__ = (2, 6, 4)
+8 -3
View File
@@ -603,8 +603,10 @@ def handle_update(data: dict, token_info: dict):
if set(add) - {"category", "photo"}:
raise MicropubValidationError("Only category and photo can be added to")
from starpunk.tags import get_note_tags
title, body = split_title(note.content)
tags = [t["display_name"] for t in note.tags]
tags = [t["display_name"] for t in get_note_tags(note.id, entered_order=True)]
photos = _note_photos(note)
changes = {}
@@ -717,8 +719,11 @@ def note_to_mf2(note, wanted: Optional[list] = None) -> dict:
}
if title:
props["name"] = [title]
if note.tags:
props["category"] = [tag["display_name"] for tag in note.tags]
from starpunk.tags import get_note_tags
tags = get_note_tags(note.id, entered_order=True)
if tags:
props["category"] = [tag["display_name"] for tag in tags]
if getattr(note, "in_reply_to", None):
props["in-reply-to"] = [note.in_reply_to]
if getattr(note, "like_of", None):
+2 -2
View File
@@ -226,8 +226,8 @@ def edit_note_form(note_id: int):
flash("Note not found", "error")
return redirect(url_for("admin.dashboard")), 404
# Pre-load tags for the edit form (v1.3.0 Phase 3)
tags = get_note_tags(note.id)
# Pre-load tags for the edit form (v1.3.0 Phase 3), as entered so saving keeps the order
tags = get_note_tags(note.id, entered_order=True)
object.__setattr__(note, '_cached_tags', tags)
from starpunk.syndication import get_note_syndications, get_targets
+1 -1
View File
@@ -1239,7 +1239,7 @@ def _reconcile(row, target: Target) -> tuple:
post = Post(
note=note,
permalink=f"{site}/note/{note.slug}",
tags=[t["display_name"] for t in get_note_tags(note.id)],
tags=[t["display_name"] for t in get_note_tags(note.id, entered_order=True)],
max_chars=target.max_chars,
media=_media_files(note.id, target.max_media) if note.kind == "note" else [],
kind=note.kind,
+11 -6
View File
@@ -115,27 +115,32 @@ def add_tags_to_note(note_id: int, tags: list[str]) -> None:
db.commit()
def get_note_tags(note_id: int) -> list[dict]:
def get_note_tags(note_id: int, entered_order: bool = False) -> list[dict]:
"""
Get all tags for a note
Args:
note_id: Note database ID
entered_order: In the order they were entered (the first is the
note's main tag, e.g. its Threads topic) instead of alphabetical.
add_tags_to_note() rewrites the links in entry order on every
save, so note_tags.id records it. Use this wherever the tags are
saved back (editor, Micropub update) so the order survives.
Returns:
List of tag dicts with 'name' and 'display_name'
Ordered alphabetically by display_name (case-insensitive)
Query should use: ORDER BY LOWER(tags.display_name) ASC
Ordered alphabetically by display_name (case-insensitive), unless
entered_order
"""
db = get_db(current_app)
order = "note_tags.id" if entered_order else "LOWER(tags.display_name)"
tags = db.execute(
"""
f"""
SELECT tags.name, tags.display_name
FROM tags
JOIN note_tags ON tags.id = note_tags.tag_id
WHERE note_tags.note_id = ?
ORDER BY LOWER(tags.display_name) ASC
ORDER BY {order} ASC
""",
(note_id,)
).fetchall()
+1 -1
View File
@@ -118,7 +118,7 @@ class TestUpdate:
def test_categories(self, app, client, h):
url = create(client, h, category=["one", "two"])
self.update(client, h, url, add={"category": ["three", "One"]})
assert source(client, h, url)["properties"]["category"] == ["one", "three", "two"]
assert source(client, h, url)["properties"]["category"] == ["one", "two", "three"] # entered order (v2.6.4)
self.update(client, h, url, delete={"category": ["two"]})
assert source(client, h, url)["properties"]["category"] == ["one", "three"]
self.update(client, h, url, delete=["category"])
+86
View File
@@ -0,0 +1,86 @@
"""
Tags keep the order they were entered in (v2.6.4)
Public pages list tags alphabetically; crossposts (the Threads topic, which
tags fit on Bluesky), the editor and Micropub use the entered order, and
saving from the editor or Micropub keeps it.
"""
import pytest
from starpunk import create_app
from starpunk.auth import create_session
from starpunk.indieauth import create_access_token
from starpunk.notes import create_note, get_note
from starpunk.tags import get_note_tags
ENTERED = ["Zebra", "apple", "Mango"]
@pytest.fixture
def app(tmp_path):
data = tmp_path / "data"
data.mkdir()
yield create_app(config={
"TESTING": True, "DATABASE_PATH": data / "starpunk.db", "DATA_PATH": data,
"NOTES_PATH": data / "notes", "SESSION_SECRET": "s", "ADMIN_ME": "https://test.example.com",
"SITE_URL": "http://localhost:5000", "DEV_MODE": False,
})
@pytest.fixture
def note(app):
with app.test_request_context():
return create_note(content="Tagged", published=True, tags=ENTERED)
def names(app, note_id, **kw):
with app.app_context():
return [t["display_name"] for t in get_note_tags(note_id, **kw)]
def test_alphabetical_by_default_entered_on_request(app, note):
assert names(app, note.id) == ["apple", "Mango", "Zebra"]
assert names(app, note.id, entered_order=True) == ENTERED
def test_public_page_stays_alphabetical(app, note):
html = app.test_client().get(f"/note/{note.slug}").data.decode()
assert html.index(">apple<") < html.index(">Mango<") < html.index(">Zebra<")
def test_editor_shows_and_keeps_entered_order(app, note):
client = app.test_client()
with app.test_request_context():
client.set_cookie("starpunk_session", create_session("https://test.example.com"))
html = client.get(f"/admin/edit/{note.id}").data.decode()
assert 'value="Zebra, apple, Mango"' in html
# Saving the form unchanged keeps the order
response = client.post(f"/admin/edit/{note.id}", data={
"content": "Tagged, edited", "published": "on", "tags": "Zebra, apple, Mango"})
assert response.status_code in (200, 302)
assert names(app, note.id, entered_order=True) == ENTERED
def test_micropub_source_and_update_keep_entered_order(app, note):
with app.test_request_context():
token = create_access_token("https://quill.example/", "create update")["access_token"]
client = app.test_client()
auth = {"Authorization": f"Bearer {token}"}
url = f"http://localhost:5000/note/{note.slug}"
source = client.get(f"/micropub?q=source&url={url}", headers=auth).get_json()
assert source["properties"]["category"] == ENTERED
response = client.post("/micropub", headers=auth, json={
"action": "update", "url": url, "add": {"category": ["Kiwi"]}})
assert response.status_code in (200, 204), response.get_data(as_text=True)
assert names(app, note.id, entered_order=True) == ENTERED + ["Kiwi"]
def test_crossposts_use_entered_order(app, note):
from starpunk.syndication import compose_text, threads_topic
tags = names(app, note.id, entered_order=True)
assert threads_topic(tags) == "Zebra"
with app.app_context():
text = compose_text(get_note(id=note.id, load_content=True),
"https://x.example/note/1", tags, 25)
assert "#Zebra" in text and "#Mango" not in text # room for the first tags only