Spaces:
Running
feat: the front door — front page, library links, weak-match notice, search-engine basics (doc 06, 2026-11-17)
Browse files- / shows a front page to new visitors instead of redirecting to the
onboarding form: search box and examples, "Personalise your feed", how the
feed works, and the week's 7 most upvoted papers as cards with Save/Pass
(policy welcome_top_v1, logged to feed_exposures). 8 of the first 18
outside readers never reached a feed.
- Library > Other devices: one private link (/l/<token>, 128 random bits,
never the user id) opens the same library in another browser. A browser
with its own saves is asked first, then its saves and follows are added.
Switching POSTs must be same-site. library_links replicates to Turso.
- A search whose best cross-encoded match is below SEARCH_WEAK_MATCH = 0.15
says "None of these is a close match" and skips the AI overview. Measured:
flags 10/30 everyday web searches, 1/100 known-answer research queries,
0/30 short real queries.
- /robots.txt and /sitemap.xml; og:url and canonical from PUBLIC_URL (https);
preview picture = the paper's first raster figure or static/og.png;
noindex on search, Library, onboarding and admin; Share on paper pages.
- Onboarding cards for physics and maths areas say how much of their older
literature the corpus holds (measured from the sidecar).
- Copy: one save starts a personal feed (was "five").
Tests: 23 new (tests/test_front_door.py) + 2 paper-page; 1,754 offline,
12 browser and 41 seeded-browser tests pass.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- CLAUDE.md +8 -4
- app/config.py +26 -0
- app/db.py +54 -0
- app/hybrid_search_svc.py +3 -0
- app/main.py +14 -15
- app/rate_limit.py +4 -0
- app/routers/library.py +151 -0
- app/routers/onboarding.py +2 -1
- app/routers/paper.py +13 -0
- app/routers/saved.py +8 -0
- app/routers/search.py +9 -2
- app/routers/seo.py +110 -0
- app/routers/welcome.py +59 -0
- app/static/app.js +17 -0
- app/static/og.png +0 -0
- app/static/styles.css +71 -2
- app/templates/base.html +19 -5
- app/templates/library_devices.html +81 -0
- app/templates/library_open.html +36 -0
- app/templates/onboarding.html +2 -0
- app/templates/paper_v2.html +3 -0
- app/templates/partials/library_tabs.html +2 -1
- app/templates/partials/search_results.html +10 -1
- app/templates/saved.html +9 -4
- app/templates/welcome.html +75 -0
- app/templates_env.py +1 -0
- app/turso_sync.py +14 -0
- docs/CURRENT-STATE.md +5 -1
- docs/research/06-Deep-Research-Verdict.md +55 -0
- scripts/build_og_image.py +57 -0
- tests/test_discovery_journey.py +4 -2
- tests/test_e2e_feed_v2.py +1 -1
- tests/test_feed_header.py +2 -2
- tests/test_front_door.py +326 -0
- tests/test_integration.py +3 -9
- tests/test_paper_page_v2.py +15 -0
|
@@ -2,7 +2,7 @@
|
|
| 2 |
|
| 3 |
> **Read this file first, every session, before touching anything else.** This file tells you which docs to trust, in what order, and the non-negotiable rules for this codebase. If you skip this file you will produce code that contradicts months of architectural research.
|
| 4 |
>
|
| 5 |
-
> **Last updated**: 2026-11-
|
| 6 |
|
| 7 |
---
|
| 8 |
|
|
@@ -78,6 +78,7 @@ These are the hard architectural commitments. **Violating any of these is a regr
|
|
| 78 |
### 3.1 Fusion
|
| 79 |
|
| 80 |
- **Search uses RRF.** (Different retrievers — dense + sparse — answering the same query. Rank fusion needs no score calibration across retrievers.) **Retained for robustness, not because it measures better** — OpenSearch's BEIR comparison puts RRF 3.86% below tuned score normalization on average and 4.81% below on SciDocs, the closest dataset to this corpus. Do not switch on that evidence alone: normalization only wins *tuned*, and this project has no ground truth to tune against yet. Land the sparse arm and an eval harness first, then settle it on our own data. See the 2026-08-12 entry in doc 06's changelog.
|
|
|
|
| 81 |
- **Search results are kept in memory for 10 minutes** (`app/search_cache.py`; 2 when a retrieval arm was missing). Callers get copies, so per-reader fields (saved, `query_id`, position) never reach the shared entry. A reader returning to the same cached results keeps their `query_id` and is not logged again (doc 06, 2026-10-21).
|
| 82 |
- **Search uses independent FTS5 lexical retrieval by default** when the sidecar is available. Failed BGE encodings must not disable FTS5. Without an FTS index search is dense-only; the Zilliz sparse fallback was removed (doc 06, 2026-11-13). RRF fuses actual available result lists; do not confuse configured backends with successful retrieval. One exception, switch `SEARCH_REWRITE_KEYWORDS`: a query the rewriter changed whose words no single paper contains leaves its own keyword list out (doc 06, 2026-10-23); its dense list and the title boost stay.
|
| 83 |
- **Recommendations use importance-weighted quota with a floor.** (Different queries — K medoid queries — over the same user. RRF would let the dominant cluster dominate; quota preserves minor interests.)
|
|
@@ -138,6 +139,7 @@ If you find `alpha_long = 0.10` anywhere in code or config, it is a bug from doc
|
|
| 138 |
- **Never restore `propensity: 1.0` on a tier that has any randomness.** A degenerate propensity makes all later IPS/SNIPS/DR analysis impossible, which defeats §3.11. `_cold_start_order()` records the conditional probability at the selected slot. This is not automatically a marginal inclusion probability or a validated IPS estimator; document conditioning before counterfactual analysis.
|
| 139 |
- Prefer epsilon-greedy over Plackett-Luce/softmax here: its propensities are exactly computable in the form §3.11 already documents. Approximate propensities are silently biased estimates.
|
| 140 |
- `feed_impressions`, `feed_exposures` and `collection_follows` **are** replicated to Turso (doc 06, 2026-11-13). Before that every deploy showed returning readers last week's papers again, dropped follows, and restarted the exposure log. An unfollow keeps its row with `active = 0` so replication carries it.
|
|
|
|
| 141 |
|
| 142 |
### 3.5 Diversity
|
| 143 |
|
|
@@ -156,7 +158,7 @@ If you find `alpha_long = 0.10` anywhere in code or config, it is a bug from doc
|
|
| 156 |
|
| 157 |
### 3.6 Cold start / onboarding (the hybrid verdict)
|
| 158 |
|
| 159 |
-
IMPLEMENTED: category/seed onboarding, starter suggestions, a described interest ("In a sentence": suggests areas and opens the seed step on its papers; doc 06, 2026-10-23), and editable `/interests`. ORCID / Scholar import was removed from the current roadmap. The right onboarding is **three-layer hybrid**:
|
| 160 |
|
| 161 |
1. arXiv category multi-select — used as a **filter and LightGBM feature**, NOT as the primary user vector.
|
| 162 |
2. Author import is historical context, not a currently planned implementation.
|
|
@@ -218,6 +220,8 @@ Ranked-surface interactions must preserve available **`query_id`**, **`propensit
|
|
| 218 |
|
| 219 |
Card saves, passes and clicks also carry `layout` (`list` or `grid2`); split any position or CTR analysis by it, since two columns change how position relates to attention. Paper titles named in a search overview link to the paper (`app/overview_links.py`, added after escaping, never model markup); those links carry the search's `query_id` and the paper's rank with `sf=search_overview`, so their clicks never pass for result-list clicks.
|
| 220 |
|
|
|
|
|
|
|
| 221 |
**When adding a new recommendation tier or call path**, always include these three fields in the `paper_tags` dict. The round-trip is: `recommendations.py` → paper dict → `action_buttons.html` `hx-vals` → `events.py` Form params → `db.log_interaction()`.
|
| 222 |
|
| 223 |
---
|
|
@@ -494,10 +498,10 @@ If a topic is too large for a 06 changelog entry, create `docs/research/07-[topi
|
|
| 494 |
| Embedding model? | BAAI/bge-m3, 1024-dim dense + sparse lexical weights, pinned to commit `5617a9f6` (`config.BGE_M3_PINS`; Dockerfile and ingest use the same). Loaded at startup in `app/embed_svc.py`. Graceful fallback if not installed. |
|
| 495 |
| How to run? | `python run.py` at http://127.0.0.1:7860 (port 7860 for HF Spaces compat) |
|
| 496 |
| How to test? | `python -m pytest tests/ -v` |
|
| 497 |
-
| Storage? | SQLite + periodic Turso replication of the user tables (interactions, profiles, clusters, onboarding, impressions, exposures, follows) and the paid-for caches. |
|
| 498 |
| Deployment? | Hugging Face Spaces (Docker SDK, 16GB RAM, 2 vCPUs). Render abandoned (512MB too small for BGE-M3). |
|
| 499 |
| Forbidden in v1? | Redis, React SPA, real-time streaming, custom embedding fine-tuning, cross-encoder in recommendation hot path, DPPs, generative retrieval. |
|
| 500 |
|
| 501 |
---
|
| 502 |
|
| 503 |
-
*Last updated: 2026-11-
|
|
|
|
| 2 |
|
| 3 |
> **Read this file first, every session, before touching anything else.** This file tells you which docs to trust, in what order, and the non-negotiable rules for this codebase. If you skip this file you will produce code that contradicts months of architectural research.
|
| 4 |
>
|
| 5 |
+
> **Last updated**: 2026-11-17
|
| 6 |
|
| 7 |
---
|
| 8 |
|
|
|
|
| 78 |
### 3.1 Fusion
|
| 79 |
|
| 80 |
- **Search uses RRF.** (Different retrievers — dense + sparse — answering the same query. Rank fusion needs no score calibration across retrievers.) **Retained for robustness, not because it measures better** — OpenSearch's BEIR comparison puts RRF 3.86% below tuned score normalization on average and 4.81% below on SciDocs, the closest dataset to this corpus. Do not switch on that evidence alone: normalization only wins *tuned*, and this project has no ground truth to tune against yet. Land the sparse arm and an eval harness first, then settle it on our own data. See the 2026-08-12 entry in doc 06's changelog.
|
| 81 |
+
- **A search with no close match says so** (best cross-encoded probability below `SEARCH_WEAK_MATCH = 0.15`): results stay, the AI overview is skipped (doc 06, 2026-11-17).
|
| 82 |
- **Search results are kept in memory for 10 minutes** (`app/search_cache.py`; 2 when a retrieval arm was missing). Callers get copies, so per-reader fields (saved, `query_id`, position) never reach the shared entry. A reader returning to the same cached results keeps their `query_id` and is not logged again (doc 06, 2026-10-21).
|
| 83 |
- **Search uses independent FTS5 lexical retrieval by default** when the sidecar is available. Failed BGE encodings must not disable FTS5. Without an FTS index search is dense-only; the Zilliz sparse fallback was removed (doc 06, 2026-11-13). RRF fuses actual available result lists; do not confuse configured backends with successful retrieval. One exception, switch `SEARCH_REWRITE_KEYWORDS`: a query the rewriter changed whose words no single paper contains leaves its own keyword list out (doc 06, 2026-10-23); its dense list and the title boost stay.
|
| 84 |
- **Recommendations use importance-weighted quota with a floor.** (Different queries — K medoid queries — over the same user. RRF would let the dominant cluster dominate; quota preserves minor interests.)
|
|
|
|
| 139 |
- **Never restore `propensity: 1.0` on a tier that has any randomness.** A degenerate propensity makes all later IPS/SNIPS/DR analysis impossible, which defeats §3.11. `_cold_start_order()` records the conditional probability at the selected slot. This is not automatically a marginal inclusion probability or a validated IPS estimator; document conditioning before counterfactual analysis.
|
| 140 |
- Prefer epsilon-greedy over Plackett-Luce/softmax here: its propensities are exactly computable in the form §3.11 already documents. Approximate propensities are silently biased estimates.
|
| 141 |
- `feed_impressions`, `feed_exposures` and `collection_follows` **are** replicated to Turso (doc 06, 2026-11-13). Before that every deploy showed returning readers last week's papers again, dropped follows, and restarted the exposure log. An unfollow keeps its row with `active = 0` so replication carries it.
|
| 142 |
+
- **A reader's library opens elsewhere from one private link** (`/l/<token>`, `app/routers/library.py`; doc 06, 2026-11-17). The token is never the user id. A browser with saves of its own is asked before switching, then its saves are added; switching POSTs must be same-site. `library_links` replicates; a replaced link keeps its row with `revoked = 1`.
|
| 143 |
|
| 144 |
### 3.5 Diversity
|
| 145 |
|
|
|
|
| 158 |
|
| 159 |
### 3.6 Cold start / onboarding (the hybrid verdict)
|
| 160 |
|
| 161 |
+
IMPLEMENTED: a front page at `/` for visitors without a finished onboarding (search, the week's papers, "Personalise your feed"; never a redirect to the form; doc 06, 2026-11-17), category/seed onboarding, starter suggestions, a described interest ("In a sentence": suggests areas and opens the seed step on its papers; doc 06, 2026-10-23), and editable `/interests`. ORCID / Scholar import was removed from the current roadmap. The right onboarding is **three-layer hybrid**:
|
| 162 |
|
| 163 |
1. arXiv category multi-select — used as a **filter and LightGBM feature**, NOT as the primary user vector.
|
| 164 |
2. Author import is historical context, not a currently planned implementation.
|
|
|
|
| 220 |
|
| 221 |
Card saves, passes and clicks also carry `layout` (`list` or `grid2`); split any position or CTR analysis by it, since two columns change how position relates to attention. Paper titles named in a search overview link to the paper (`app/overview_links.py`, added after escaping, never model markup); those links carry the search's `query_id` and the paper's rank with `sf=search_overview`, so their clicks never pass for result-list clicks.
|
| 222 |
|
| 223 |
+
The front page's week cards are a ranked surface too (`policy_id = welcome_top_v1`, logged to `feed_exposures`).
|
| 224 |
+
|
| 225 |
**When adding a new recommendation tier or call path**, always include these three fields in the `paper_tags` dict. The round-trip is: `recommendations.py` → paper dict → `action_buttons.html` `hx-vals` → `events.py` Form params → `db.log_interaction()`.
|
| 226 |
|
| 227 |
---
|
|
|
|
| 498 |
| Embedding model? | BAAI/bge-m3, 1024-dim dense + sparse lexical weights, pinned to commit `5617a9f6` (`config.BGE_M3_PINS`; Dockerfile and ingest use the same). Loaded at startup in `app/embed_svc.py`. Graceful fallback if not installed. |
|
| 499 |
| How to run? | `python run.py` at http://127.0.0.1:7860 (port 7860 for HF Spaces compat) |
|
| 500 |
| How to test? | `python -m pytest tests/ -v` |
|
| 501 |
+
| Storage? | SQLite + periodic Turso replication of the user tables (interactions, profiles, clusters, onboarding, impressions, exposures, follows, library links) and the paid-for caches. |
|
| 502 |
| Deployment? | Hugging Face Spaces (Docker SDK, 16GB RAM, 2 vCPUs). Render abandoned (512MB too small for BGE-M3). |
|
| 503 |
| Forbidden in v1? | Redis, React SPA, real-time streaming, custom embedding fine-tuning, cross-encoder in recommendation hot path, DPPs, generative retrieval. |
|
| 504 |
|
| 505 |
---
|
| 506 |
|
| 507 |
+
*Last updated: 2026-11-17. Update this date when CLAUDE.md changes.*
|
|
@@ -443,6 +443,13 @@ SEARCH_FTS_BUDGET_MS = int(os.getenv("SEARCH_FTS_BUDGET_MS", "1500"))
|
|
| 443 |
# Recent search results kept in memory (app/search_cache.py), so going back to a
|
| 444 |
# search doesn't run it again. A search missing one retrieval arm is kept briefly,
|
| 445 |
# since a later run may do better. 0 turns the cache off.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 446 |
SEARCH_CACHE_TTL_S = int(os.getenv("SEARCH_CACHE_TTL_S", "600"))
|
| 447 |
SEARCH_CACHE_DEGRADED_TTL_S = int(os.getenv("SEARCH_CACHE_DEGRADED_TTL_S", "120"))
|
| 448 |
|
|
@@ -582,6 +589,25 @@ CATEGORY_GROUPS: dict[str, dict] = {
|
|
| 582 |
},
|
| 583 |
}
|
| 584 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 585 |
|
| 586 |
def expand_category_groups(group_keys: list[str]) -> set[str]:
|
| 587 |
"""Convert a list of group keys (e.g. ['nlp', 'cv']) into a flat set of arXiv categories."""
|
|
|
|
| 443 |
# Recent search results kept in memory (app/search_cache.py), so going back to a
|
| 444 |
# search doesn't run it again. A search missing one retrieval arm is kept briefly,
|
| 445 |
# since a later run may do better. 0 turns the cache off.
|
| 446 |
+
# A search whose best cross-encoded match scores below this (sigmoid of the
|
| 447 |
+
# logit) says so above its results and skips the AI overview. Measured
|
| 448 |
+
# 2026-11-17 (doc 06): 0.15 flags 10 of 30 everyday web searches ("recipe for
|
| 449 |
+
# butter chicken", "Paytm product manager questions") and 1 of 100 known-answer
|
| 450 |
+
# research queries, none of 30 short real ones ("lora", "mamba"). 0 turns it off.
|
| 451 |
+
SEARCH_WEAK_MATCH = float(os.getenv("SEARCH_WEAK_MATCH", "0.15"))
|
| 452 |
+
|
| 453 |
SEARCH_CACHE_TTL_S = int(os.getenv("SEARCH_CACHE_TTL_S", "600"))
|
| 454 |
SEARCH_CACHE_DEGRADED_TTL_S = int(os.getenv("SEARCH_CACHE_DEGRADED_TTL_S", "120"))
|
| 455 |
|
|
|
|
| 589 |
},
|
| 590 |
}
|
| 591 |
|
| 592 |
+
# Areas the corpus covers only in part before mid-2025, shown on their onboarding
|
| 593 |
+
# card. The original snapshot left out 700,939 physics and maths papers (hep-ph
|
| 594 |
+
# 125k, hep-th 96k, cond-mat 134k, astro-ph 104k); everything since 2025-06 comes
|
| 595 |
+
# in daily. Measured 2026-11-17 in the sidecar as papers from 2024 against the
|
| 596 |
+
# 12 months from 2025-07, by primary category: these fields grow a few percent a
|
| 597 |
+
# year, so the ratio is close to the share we hold. CS and ML are complete.
|
| 598 |
+
AREA_COVERAGE_NOTES: dict[str, str] = {
|
| 599 |
+
"hep": "Before mid-2025: about 1 in 5 papers",
|
| 600 |
+
"cond_mat": "Before mid-2025: about 1 in 3 papers",
|
| 601 |
+
"astro": "Before mid-2025: about 2 in 5 papers",
|
| 602 |
+
"pde": "Before mid-2025: about half the papers",
|
| 603 |
+
"math": "Before mid-2025: some fields partial",
|
| 604 |
+
}
|
| 605 |
+
|
| 606 |
+
# The address readers reach the app at. Behind the Space's proxy the request
|
| 607 |
+
# arrives as http://, so links that leave the site (share previews, the
|
| 608 |
+
# sitemap, library links) are built from this instead of from the request.
|
| 609 |
+
PUBLIC_URL = os.getenv("PUBLIC_URL", "https://siddhm11-researchit.hf.space").strip().rstrip("/")
|
| 610 |
+
|
| 611 |
|
| 612 |
def expand_category_groups(group_keys: list[str]) -> set[str]:
|
| 613 |
"""Convert a list of group keys (e.g. ['nlp', 'cv']) into a flat set of arXiv categories."""
|
|
@@ -434,6 +434,20 @@ CREATE TABLE IF NOT EXISTS collection_follows (
|
|
| 434 |
);
|
| 435 |
CREATE INDEX IF NOT EXISTS idx_follow_user
|
| 436 |
ON collection_follows(user_id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 437 |
"""
|
| 438 |
|
| 439 |
|
|
@@ -1224,6 +1238,46 @@ async def unfollow_collection(user_id: str, slug: str) -> None:
|
|
| 1224 |
await conn.commit()
|
| 1225 |
|
| 1226 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1227 |
async def get_followed_slugs(user_id: str) -> set[str]:
|
| 1228 |
if not user_id:
|
| 1229 |
return set()
|
|
|
|
| 434 |
);
|
| 435 |
CREATE INDEX IF NOT EXISTS idx_follow_user
|
| 436 |
ON collection_follows(user_id);
|
| 437 |
+
|
| 438 |
+
-- A private link that opens a reader's library in another browser
|
| 439 |
+
-- (app/routers/library.py). One live link per reader; making a new one sets
|
| 440 |
+
-- revoked = 1 on the old row, which keeps it so replication carries the change.
|
| 441 |
+
CREATE TABLE IF NOT EXISTS library_links (
|
| 442 |
+
token TEXT PRIMARY KEY,
|
| 443 |
+
user_id TEXT NOT NULL,
|
| 444 |
+
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
| 445 |
+
revoked INTEGER NOT NULL DEFAULT 0,
|
| 446 |
+
updated_at TEXT NOT NULL DEFAULT (datetime('now')),
|
| 447 |
+
uses INTEGER NOT NULL DEFAULT 0
|
| 448 |
+
);
|
| 449 |
+
CREATE INDEX IF NOT EXISTS idx_library_links_user
|
| 450 |
+
ON library_links(user_id);
|
| 451 |
"""
|
| 452 |
|
| 453 |
|
|
|
|
| 1238 |
await conn.commit()
|
| 1239 |
|
| 1240 |
|
| 1241 |
+
# ── Library links (app/routers/library.py) ───────────────────────────────────
|
| 1242 |
+
|
| 1243 |
+
async def get_library_link(user_id: str) -> str | None:
|
| 1244 |
+
"""The reader's live link token, or None."""
|
| 1245 |
+
async with aiosqlite.connect(DB_PATH) as conn:
|
| 1246 |
+
row = await (await conn.execute(
|
| 1247 |
+
"SELECT token FROM library_links WHERE user_id = ? AND revoked = 0 "
|
| 1248 |
+
"ORDER BY created_at DESC LIMIT 1", (user_id,))).fetchone()
|
| 1249 |
+
return row[0] if row else None
|
| 1250 |
+
|
| 1251 |
+
|
| 1252 |
+
async def create_library_link(user_id: str, token: str) -> None:
|
| 1253 |
+
"""Make `token` the reader's only live link; earlier ones stop working."""
|
| 1254 |
+
async with aiosqlite.connect(DB_PATH) as conn:
|
| 1255 |
+
await conn.execute(
|
| 1256 |
+
"UPDATE library_links SET revoked = 1, updated_at = datetime('now') "
|
| 1257 |
+
"WHERE user_id = ? AND revoked = 0", (user_id,))
|
| 1258 |
+
await conn.execute("INSERT INTO library_links (token, user_id) VALUES (?, ?)", (token, user_id))
|
| 1259 |
+
await conn.commit()
|
| 1260 |
+
|
| 1261 |
+
|
| 1262 |
+
async def revoke_library_link(user_id: str) -> None:
|
| 1263 |
+
async with aiosqlite.connect(DB_PATH) as conn:
|
| 1264 |
+
await conn.execute(
|
| 1265 |
+
"UPDATE library_links SET revoked = 1, updated_at = datetime('now') "
|
| 1266 |
+
"WHERE user_id = ? AND revoked = 0", (user_id,))
|
| 1267 |
+
await conn.commit()
|
| 1268 |
+
|
| 1269 |
+
|
| 1270 |
+
async def resolve_library_link(token: str) -> str | None:
|
| 1271 |
+
"""The user a live link opens, counting the use; None for an unknown or old link."""
|
| 1272 |
+
async with aiosqlite.connect(DB_PATH) as conn:
|
| 1273 |
+
row = await (await conn.execute(
|
| 1274 |
+
"SELECT user_id FROM library_links WHERE token = ? AND revoked = 0", (token,))).fetchone()
|
| 1275 |
+
if row:
|
| 1276 |
+
await conn.execute("UPDATE library_links SET uses = uses + 1 WHERE token = ?", (token,))
|
| 1277 |
+
await conn.commit()
|
| 1278 |
+
return row[0] if row else None
|
| 1279 |
+
|
| 1280 |
+
|
| 1281 |
async def get_followed_slugs(user_id: str) -> set[str]:
|
| 1282 |
if not user_id:
|
| 1283 |
return set()
|
|
@@ -356,6 +356,9 @@ async def search(
|
|
| 356 |
except OverflowError:
|
| 357 |
bge_prob = 0.0 if bge_score < 0 else 1.0
|
| 358 |
bge_scores_by_id[p["arxiv_id"]] = bge_prob
|
|
|
|
|
|
|
|
|
|
| 359 |
|
| 360 |
# Narrow to the cross-encoded window.
|
| 361 |
#
|
|
|
|
| 356 |
except OverflowError:
|
| 357 |
bge_prob = 0.0 if bge_score < 0 else 1.0
|
| 358 |
bge_scores_by_id[p["arxiv_id"]] = bge_prob
|
| 359 |
+
if bge_scores_by_id:
|
| 360 |
+
# How well the best paper matches at all, for the weak-match notice.
|
| 361 |
+
search_meta["ce_top"] = round(max(bge_scores_by_id.values()), 4)
|
| 362 |
|
| 363 |
# Narrow to the cross-encoded window.
|
| 364 |
#
|
|
@@ -14,7 +14,7 @@ from contextlib import asynccontextmanager
|
|
| 14 |
from datetime import datetime, timezone
|
| 15 |
|
| 16 |
from fastapi import FastAPI, Request, Cookie
|
| 17 |
-
from fastapi.responses import (HTMLResponse, JSONResponse,
|
| 18 |
PlainTextResponse)
|
| 19 |
from fastapi.middleware.gzip import GZipMiddleware
|
| 20 |
from fastapi.staticfiles import StaticFiles
|
|
@@ -22,7 +22,7 @@ from app import db
|
|
| 22 |
from app.config import APP_TITLE, COOKIE_NAME, COOKIE_MAX_AGE
|
| 23 |
from app.templates_env import templates
|
| 24 |
from app.routers import (admin, search, events, recommendations, saved, onboarding,
|
| 25 |
-
health, collections, paper, figures, trending)
|
| 26 |
|
| 27 |
|
| 28 |
@asynccontextmanager
|
|
@@ -253,6 +253,8 @@ app.include_router(collections.router)
|
|
| 253 |
app.include_router(paper.router)
|
| 254 |
app.include_router(figures.router)
|
| 255 |
app.include_router(admin.router)
|
|
|
|
|
|
|
| 256 |
# researchit-space (3D map client) JSON API. Guarded the same way as the Turso
|
| 257 |
# sync and BGE-M3 warmup above: this router is additive, and a fault inside it
|
| 258 |
# must never stop the main app from serving.
|
|
@@ -270,27 +272,24 @@ async def home(
|
|
| 270 |
):
|
| 271 |
user_id = user_id or str(uuid.uuid4())
|
| 272 |
|
| 273 |
-
#
|
| 274 |
-
#
|
|
|
|
|
|
|
|
|
|
| 275 |
onboarding_state = await db.get_onboarding_state(user_id)
|
| 276 |
-
if onboarding_state is None:
|
| 277 |
-
#
|
| 278 |
-
#
|
| 279 |
-
# shared-link visitors straight past onboarding for good.
|
| 280 |
interactions = await db.get_user_interactions(
|
| 281 |
user_id, event_types=["save", "unsave", "not_interested"], limit=1)
|
| 282 |
if interactions:
|
| 283 |
-
# Auto-mark as onboarded — don't interrupt returning users
|
| 284 |
await db.complete_onboarding(user_id)
|
| 285 |
else:
|
| 286 |
-
|
| 287 |
-
resp =
|
| 288 |
resp.set_cookie(COOKIE_NAME, user_id, max_age=COOKIE_MAX_AGE, httponly=True)
|
| 289 |
return resp
|
| 290 |
-
elif not onboarding_state["onboarding_completed"]:
|
| 291 |
-
resp = RedirectResponse("/onboarding", status_code=302)
|
| 292 |
-
resp.set_cookie(COOKIE_NAME, user_id, max_age=COOKIE_MAX_AGE, httponly=True)
|
| 293 |
-
return resp
|
| 294 |
|
| 295 |
from app import user_state as us
|
| 296 |
state = await us.ensure_loaded(user_id)
|
|
|
|
| 14 |
from datetime import datetime, timezone
|
| 15 |
|
| 16 |
from fastapi import FastAPI, Request, Cookie
|
| 17 |
+
from fastapi.responses import (HTMLResponse, JSONResponse,
|
| 18 |
PlainTextResponse)
|
| 19 |
from fastapi.middleware.gzip import GZipMiddleware
|
| 20 |
from fastapi.staticfiles import StaticFiles
|
|
|
|
| 22 |
from app.config import APP_TITLE, COOKIE_NAME, COOKIE_MAX_AGE
|
| 23 |
from app.templates_env import templates
|
| 24 |
from app.routers import (admin, search, events, recommendations, saved, onboarding,
|
| 25 |
+
health, collections, paper, figures, trending, library, seo)
|
| 26 |
|
| 27 |
|
| 28 |
@asynccontextmanager
|
|
|
|
| 253 |
app.include_router(paper.router)
|
| 254 |
app.include_router(figures.router)
|
| 255 |
app.include_router(admin.router)
|
| 256 |
+
app.include_router(library.router)
|
| 257 |
+
app.include_router(seo.router)
|
| 258 |
# researchit-space (3D map client) JSON API. Guarded the same way as the Turso
|
| 259 |
# sync and BGE-M3 warmup above: this router is additive, and a fault inside it
|
| 260 |
# must never stop the main app from serving.
|
|
|
|
| 272 |
):
|
| 273 |
user_id = user_id or str(uuid.uuid4())
|
| 274 |
|
| 275 |
+
# A visitor without a finished onboarding gets the front page, not the
|
| 276 |
+
# form (doc 06, 2026-11-17): search and the week's papers first, with
|
| 277 |
+
# "Personalise your feed" one click away. Anyone who has made a decision
|
| 278 |
+
# (saved, un-saved or passed, from the front page too) is marked onboarded
|
| 279 |
+
# and gets the feed.
|
| 280 |
onboarding_state = await db.get_onboarding_state(user_id)
|
| 281 |
+
if onboarding_state is None or not onboarding_state["onboarding_completed"]:
|
| 282 |
+
# Opens do not count: a direct /p/ visit logs a `view`, and treating
|
| 283 |
+
# that as history sent shared-link visitors past onboarding for good.
|
|
|
|
| 284 |
interactions = await db.get_user_interactions(
|
| 285 |
user_id, event_types=["save", "unsave", "not_interested"], limit=1)
|
| 286 |
if interactions:
|
|
|
|
| 287 |
await db.complete_onboarding(user_id)
|
| 288 |
else:
|
| 289 |
+
from app.routers import welcome
|
| 290 |
+
resp = await welcome.render(request, user_id, started=onboarding_state is not None)
|
| 291 |
resp.set_cookie(COOKIE_NAME, user_id, max_age=COOKIE_MAX_AGE, httponly=True)
|
| 292 |
return resp
|
|
|
|
|
|
|
|
|
|
|
|
|
| 293 |
|
| 294 |
from app import user_state as us
|
| 295 |
state = await us.ensure_loaded(user_id)
|
|
@@ -79,6 +79,10 @@ LIMITS: dict[str, tuple[int, int]] = {
|
|
| 79 |
"/fig": (600, 60),
|
| 80 |
"/api/ui-event": (60, 60),
|
| 81 |
"/api/space/search": (30, 60),
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
"/api/space": (120, 60),
|
| 83 |
}
|
| 84 |
|
|
|
|
| 79 |
"/fig": (600, 60),
|
| 80 |
"/api/ui-event": (60, 60),
|
| 81 |
"/api/space/search": (30, 60),
|
| 82 |
+
# Library links (app/routers/library.py): a person opens or makes one now
|
| 83 |
+
# and then; anything faster is someone guessing tokens.
|
| 84 |
+
"/l": (20, 60),
|
| 85 |
+
"/api/library-link": (10, 60),
|
| 86 |
"/api/space": (120, 60),
|
| 87 |
}
|
| 88 |
|
|
@@ -0,0 +1,151 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Your library on another device (doc 06, 2026-11-17).
|
| 3 |
+
|
| 4 |
+
A reader is a browser cookie: saves, interests and follows belong to it, so a
|
| 5 |
+
new phone or cleared cookies started over with nothing. This gives each reader
|
| 6 |
+
one private link that opens the same library in any browser, with no account
|
| 7 |
+
and no email:
|
| 8 |
+
|
| 9 |
+
GET /library/devices the link, with Copy and Share; make a new one or turn it off
|
| 10 |
+
POST /api/library-link make a new link (the old one stops working)
|
| 11 |
+
POST /api/library-link/revoke turn the link off
|
| 12 |
+
GET /l/{token} open a library from its link
|
| 13 |
+
POST /l/{token} confirm opening it in a browser that has its own saves
|
| 14 |
+
|
| 15 |
+
The token is 128 random bits and is not the user id, which appears in logs and
|
| 16 |
+
dashboards; a link that leaks is replaced in one click. Opening a link in a
|
| 17 |
+
browser that already has saves asks first, then adds that browser's saved
|
| 18 |
+
papers and follows to the linked library, so nothing a reader did is lost.
|
| 19 |
+
That POST must come from this site (Sec-Fetch-Site / Origin), so another page
|
| 20 |
+
cannot switch a visitor's library behind their back. Rows replicate to Turso
|
| 21 |
+
(turso_sync "library_links"), so links survive a deploy.
|
| 22 |
+
"""
|
| 23 |
+
from __future__ import annotations
|
| 24 |
+
|
| 25 |
+
import secrets
|
| 26 |
+
import uuid
|
| 27 |
+
from urllib.parse import urlparse
|
| 28 |
+
|
| 29 |
+
from fastapi import APIRouter, Cookie, Request
|
| 30 |
+
from fastapi.responses import HTMLResponse, RedirectResponse
|
| 31 |
+
|
| 32 |
+
from app import config, db
|
| 33 |
+
from app import user_state as us
|
| 34 |
+
from app.config import COOKIE_MAX_AGE, COOKIE_NAME
|
| 35 |
+
from app.templates_env import templates
|
| 36 |
+
|
| 37 |
+
router = APIRouter()
|
| 38 |
+
|
| 39 |
+
MERGE_SOURCE = "library_merge"
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def link_url(token: str) -> str:
|
| 43 |
+
return f"{config.PUBLIC_URL}/l/{token}"
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def _with_cookie(resp, user_id: str):
|
| 47 |
+
resp.set_cookie(COOKIE_NAME, user_id, max_age=COOKIE_MAX_AGE, httponly=True)
|
| 48 |
+
return resp
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
async def _saved_ids(user_id: str) -> list[str]:
|
| 52 |
+
"""Saved paper ids, oldest first."""
|
| 53 |
+
return [r["paper_id"] for r in reversed(await db.get_current_feedback(user_id))
|
| 54 |
+
if r["event_type"] == "save"]
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def _same_site(request: Request) -> bool:
|
| 58 |
+
site = request.headers.get("sec-fetch-site")
|
| 59 |
+
if site is not None:
|
| 60 |
+
return site in ("same-origin", "none")
|
| 61 |
+
origin = request.headers.get("origin")
|
| 62 |
+
if origin is None: # older browsers send neither on a same-site form
|
| 63 |
+
return True
|
| 64 |
+
return urlparse(origin).netloc == request.headers.get("host", "")
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
async def merge_into(from_uid: str, to_uid: str) -> int:
|
| 68 |
+
"""Add from_uid's saved papers and follows to to_uid. Returns papers added.
|
| 69 |
+
|
| 70 |
+
A paper the target already saved or passed on keeps the target's decision.
|
| 71 |
+
Each added save updates the target's profile like a save from a card."""
|
| 72 |
+
from app.routers.events import _spawn, _update_profile_on_save
|
| 73 |
+
await us.ensure_loaded(to_uid)
|
| 74 |
+
decided = {r["paper_id"] for r in await db.get_current_feedback(to_uid)}
|
| 75 |
+
added = 0
|
| 76 |
+
for pid in await _saved_ids(from_uid):
|
| 77 |
+
if pid in decided:
|
| 78 |
+
continue
|
| 79 |
+
await db.log_interaction(user_id=to_uid, paper_id=pid, event_type="save", source=MERGE_SOURCE)
|
| 80 |
+
us.record_positive(to_uid, pid)
|
| 81 |
+
_spawn(_update_profile_on_save(to_uid, pid))
|
| 82 |
+
added += 1
|
| 83 |
+
for slug in await db.get_followed_slugs(from_uid):
|
| 84 |
+
await db.follow_collection(to_uid, slug)
|
| 85 |
+
if added:
|
| 86 |
+
onboarding = await db.get_onboarding_state(to_uid)
|
| 87 |
+
if not onboarding or not onboarding["onboarding_completed"]:
|
| 88 |
+
await db.complete_onboarding(to_uid)
|
| 89 |
+
return added
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
@router.get("/library/devices", response_class=HTMLResponse)
|
| 93 |
+
async def devices_page(request: Request, user_id: str | None = Cookie(default=None, alias=COOKIE_NAME)):
|
| 94 |
+
user_id = user_id or str(uuid.uuid4())
|
| 95 |
+
token = await db.get_library_link(user_id)
|
| 96 |
+
resp = templates.TemplateResponse(request, "library_devices.html", {
|
| 97 |
+
"link": link_url(token) if token else None,
|
| 98 |
+
"count": len(await _saved_ids(user_id)),
|
| 99 |
+
"library_tab": "devices",
|
| 100 |
+
})
|
| 101 |
+
return _with_cookie(resp, user_id)
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
@router.post("/api/library-link")
|
| 105 |
+
async def make_link(request: Request, user_id: str | None = Cookie(default=None, alias=COOKIE_NAME)):
|
| 106 |
+
if not _same_site(request):
|
| 107 |
+
return HTMLResponse("This link can only be made from ResearchIT itself.", status_code=403)
|
| 108 |
+
user_id = user_id or str(uuid.uuid4())
|
| 109 |
+
await db.create_library_link(user_id, secrets.token_urlsafe(16))
|
| 110 |
+
return _with_cookie(RedirectResponse("/library/devices#link", status_code=303), user_id)
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
@router.post("/api/library-link/revoke")
|
| 114 |
+
async def revoke_link(request: Request, user_id: str | None = Cookie(default=None, alias=COOKIE_NAME)):
|
| 115 |
+
if not _same_site(request):
|
| 116 |
+
return HTMLResponse("This can only be done from ResearchIT itself.", status_code=403)
|
| 117 |
+
if user_id:
|
| 118 |
+
await db.revoke_library_link(user_id)
|
| 119 |
+
return RedirectResponse("/library/devices", status_code=303)
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
@router.get("/l/{token}", response_class=HTMLResponse)
|
| 123 |
+
async def open_link(token: str, request: Request,
|
| 124 |
+
user_id: str | None = Cookie(default=None, alias=COOKIE_NAME)):
|
| 125 |
+
target = await db.resolve_library_link(token)
|
| 126 |
+
if target is None:
|
| 127 |
+
resp = templates.TemplateResponse(request, "library_open.html", {"state": "gone"}, status_code=404)
|
| 128 |
+
return _with_cookie(resp, user_id) if user_id else resp
|
| 129 |
+
if user_id == target:
|
| 130 |
+
return RedirectResponse("/saved?opened=here", status_code=303)
|
| 131 |
+
mine = await _saved_ids(user_id) if user_id else []
|
| 132 |
+
if not mine:
|
| 133 |
+
# Nothing here to lose: open the library straight away.
|
| 134 |
+
return _with_cookie(RedirectResponse("/saved?opened=1", status_code=303), target)
|
| 135 |
+
resp = templates.TemplateResponse(request, "library_open.html", {
|
| 136 |
+
"state": "confirm", "token": token, "mine": len(mine),
|
| 137 |
+
"theirs": len(await _saved_ids(target)),
|
| 138 |
+
})
|
| 139 |
+
return _with_cookie(resp, user_id)
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
@router.post("/l/{token}", response_class=HTMLResponse)
|
| 143 |
+
async def confirm_open(token: str, request: Request,
|
| 144 |
+
user_id: str | None = Cookie(default=None, alias=COOKIE_NAME)):
|
| 145 |
+
if not _same_site(request):
|
| 146 |
+
return HTMLResponse("Open the link again and confirm on ResearchIT's own page.", status_code=403)
|
| 147 |
+
target = await db.resolve_library_link(token)
|
| 148 |
+
if target is None:
|
| 149 |
+
return templates.TemplateResponse(request, "library_open.html", {"state": "gone"}, status_code=404)
|
| 150 |
+
added = await merge_into(user_id, target) if user_id and user_id != target else 0
|
| 151 |
+
return _with_cookie(RedirectResponse(f"/saved?opened=1&added={added}", status_code=303), target)
|
|
@@ -12,7 +12,7 @@ import uuid
|
|
| 12 |
from fastapi import APIRouter, Request, Cookie, HTTPException
|
| 13 |
from fastapi.responses import HTMLResponse, JSONResponse, RedirectResponse
|
| 14 |
from app import db, discovery_svc
|
| 15 |
-
from app.config import COOKIE_NAME, COOKIE_MAX_AGE, CATEGORY_GROUPS
|
| 16 |
from app.templates_env import templates
|
| 17 |
|
| 18 |
# Reuse the hybrid search backend for seed paper discovery
|
|
@@ -100,6 +100,7 @@ async def onboarding_page(
|
|
| 100 |
"onboarding.html",
|
| 101 |
{
|
| 102 |
"categories": CATEGORY_GROUPS,
|
|
|
|
| 103 |
"selected": selected,
|
| 104 |
},
|
| 105 |
)
|
|
|
|
| 12 |
from fastapi import APIRouter, Request, Cookie, HTTPException
|
| 13 |
from fastapi.responses import HTMLResponse, JSONResponse, RedirectResponse
|
| 14 |
from app import db, discovery_svc
|
| 15 |
+
from app.config import AREA_COVERAGE_NOTES, COOKIE_NAME, COOKIE_MAX_AGE, CATEGORY_GROUPS
|
| 16 |
from app.templates_env import templates
|
| 17 |
|
| 18 |
# Reuse the hybrid search backend for seed paper discovery
|
|
|
|
| 100 |
"onboarding.html",
|
| 101 |
{
|
| 102 |
"categories": CATEGORY_GROUPS,
|
| 103 |
+
"coverage": AREA_COVERAGE_NOTES,
|
| 104 |
"selected": selected,
|
| 105 |
},
|
| 106 |
)
|
|
@@ -220,6 +220,9 @@ async def paper_page(
|
|
| 220 |
if features.visible("PAPER_PAGE_V2", request):
|
| 221 |
template = "paper_v2.html"
|
| 222 |
context.update(await _v2_context(paper, related, request, back=back_link(request, sf, qid)))
|
|
|
|
|
|
|
|
|
|
| 223 |
resp = templates.TemplateResponse(request, template, context)
|
| 224 |
resp.set_cookie(COOKIE_NAME, user_id, max_age=COOKIE_MAX_AGE, httponly=True)
|
| 225 |
# Recorded so a redesign of this page can be compared against what it
|
|
@@ -238,6 +241,16 @@ _BACK_PAGES = {"/": "Your feed", "/search": "Search results", "/saved": "Saved p
|
|
| 238 |
_BACK_PATH = re.compile(r"/collections/[a-z0-9-]{1,80}|/p/\d{4}\.\d{4,5}")
|
| 239 |
|
| 240 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 241 |
def back_link(request: Request, sf: str, qid: str) -> dict | None:
|
| 242 |
"""The paper page's link back: the page the reader came from.
|
| 243 |
|
|
|
|
| 220 |
if features.visible("PAPER_PAGE_V2", request):
|
| 221 |
template = "paper_v2.html"
|
| 222 |
context.update(await _v2_context(paper, related, request, back=back_link(request, sf, qid)))
|
| 223 |
+
image = share_image(context.get("figures") or [])
|
| 224 |
+
if image:
|
| 225 |
+
context["og_image"] = image
|
| 226 |
resp = templates.TemplateResponse(request, template, context)
|
| 227 |
resp.set_cookie(COOKIE_NAME, user_id, max_age=COOKIE_MAX_AGE, httponly=True)
|
| 228 |
# Recorded so a redesign of this page can be compared against what it
|
|
|
|
| 241 |
_BACK_PATH = re.compile(r"/collections/[a-z0-9-]{1,80}|/p/\d{4}\.\d{4,5}")
|
| 242 |
|
| 243 |
|
| 244 |
+
def share_image(figures: list[dict]) -> str | None:
|
| 245 |
+
"""The picture a shared link to this paper shows: its first raster figure.
|
| 246 |
+
SVG figures are left out because link previews (Slack, X, WhatsApp) only
|
| 247 |
+
draw raster images; without one the page keeps the site's own picture."""
|
| 248 |
+
for f in figures:
|
| 249 |
+
if f.get("url") and not f["url"].endswith(".svg"):
|
| 250 |
+
return config.PUBLIC_URL + f["url"]
|
| 251 |
+
return None
|
| 252 |
+
|
| 253 |
+
|
| 254 |
def back_link(request: Request, sf: str, qid: str) -> dict | None:
|
| 255 |
"""The paper page's link back: the page the reader came from.
|
| 256 |
|
|
@@ -79,12 +79,20 @@ async def saved_papers(
|
|
| 79 |
if aid in meta
|
| 80 |
]
|
| 81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
resp = templates.TemplateResponse(
|
| 83 |
request,
|
| 84 |
"saved.html",
|
| 85 |
{
|
| 86 |
"papers": papers,
|
| 87 |
"count": len(papers),
|
|
|
|
|
|
|
| 88 |
},
|
| 89 |
)
|
| 90 |
resp.set_cookie(COOKIE_NAME, user_id, max_age=COOKIE_MAX_AGE, httponly=True)
|
|
|
|
| 79 |
if aid in meta
|
| 80 |
]
|
| 81 |
|
| 82 |
+
# Arriving from a library link (app/routers/library.py).
|
| 83 |
+
opened = request.query_params.get("opened")
|
| 84 |
+
try:
|
| 85 |
+
added = max(0, int(request.query_params.get("added", "0")))
|
| 86 |
+
except ValueError:
|
| 87 |
+
added = 0
|
| 88 |
resp = templates.TemplateResponse(
|
| 89 |
request,
|
| 90 |
"saved.html",
|
| 91 |
{
|
| 92 |
"papers": papers,
|
| 93 |
"count": len(papers),
|
| 94 |
+
"opened": opened if opened in ("1", "here") else None,
|
| 95 |
+
"added": added,
|
| 96 |
},
|
| 97 |
)
|
| 98 |
resp.set_cookie(COOKIE_NAME, user_id, max_age=COOKIE_MAX_AGE, httponly=True)
|
|
@@ -15,7 +15,8 @@ import re
|
|
| 15 |
import uuid
|
| 16 |
from fastapi import APIRouter, Request, Cookie
|
| 17 |
from fastapi.responses import HTMLResponse, RedirectResponse, Response
|
| 18 |
-
from app import analytics, arxiv_svc, card_data, db, features, figure_prewarm,
|
|
|
|
| 19 |
from app.config import COOKIE_NAME, COOKIE_MAX_AGE, ARXIV_MAX_RESULTS
|
| 20 |
from app.templates_env import templates
|
| 21 |
|
|
@@ -204,6 +205,12 @@ async def search(
|
|
| 204 |
named = (search_meta.get("named_paper") or {}).get("arxiv_id")
|
| 205 |
for p in papers:
|
| 206 |
p["named_paper"] = bool(named) and p.get("arxiv_id") == named
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
|
| 208 |
# A small figure beside each result that already has one saved (switch
|
| 209 |
# SEARCH_FIGURES; local reads only, order and instrumentation untouched),
|
|
@@ -221,7 +228,7 @@ async def search(
|
|
| 221 |
# htmx restoring a page it has no snapshot of asks with HX-Request too, and
|
| 222 |
# swaps the answer in as the whole body, so it gets the whole page.
|
| 223 |
paging = {"page": page, "since": since, "area": area, "has_more": has_more, "start": start,
|
| 224 |
-
"years": YEARS, "areas": AREAS}
|
| 225 |
if request.headers.get("HX-Request") and not request.headers.get("HX-History-Restore-Request"):
|
| 226 |
resp = templates.TemplateResponse(
|
| 227 |
request,
|
|
|
|
| 15 |
import uuid
|
| 16 |
from fastapi import APIRouter, Request, Cookie
|
| 17 |
from fastapi.responses import HTMLResponse, RedirectResponse, Response
|
| 18 |
+
from app import (analytics, arxiv_svc, card_data, config, db, features, figure_prewarm, runtime_stats,
|
| 19 |
+
search_cache, turso_svc, user_state as us, hybrid_search_svc)
|
| 20 |
from app.config import COOKIE_NAME, COOKIE_MAX_AGE, ARXIV_MAX_RESULTS
|
| 21 |
from app.templates_env import templates
|
| 22 |
|
|
|
|
| 205 |
named = (search_meta.get("named_paper") or {}).get("arxiv_id")
|
| 206 |
for p in papers:
|
| 207 |
p["named_paper"] = bool(named) and p.get("arxiv_id") == named
|
| 208 |
+
# Nothing here is a close match (often a search that isn't about research):
|
| 209 |
+
# say so, and spend no model call on an overview of the wrong papers.
|
| 210 |
+
ce_top = search_meta.get("ce_top")
|
| 211 |
+
weak_match = bool(papers and ce_top is not None and ce_top < config.SEARCH_WEAK_MATCH and not named)
|
| 212 |
+
if weak_match and page == 1 and repeat_qid is None:
|
| 213 |
+
runtime_stats.count("search_weak_match")
|
| 214 |
|
| 215 |
# A small figure beside each result that already has one saved (switch
|
| 216 |
# SEARCH_FIGURES; local reads only, order and instrumentation untouched),
|
|
|
|
| 228 |
# htmx restoring a page it has no snapshot of asks with HX-Request too, and
|
| 229 |
# swaps the answer in as the whole body, so it gets the whole page.
|
| 230 |
paging = {"page": page, "since": since, "area": area, "has_more": has_more, "start": start,
|
| 231 |
+
"years": YEARS, "areas": AREAS, "weak_match": weak_match}
|
| 232 |
if request.headers.get("HX-Request") and not request.headers.get("HX-History-Restore-Request"):
|
| 233 |
resp = templates.TemplateResponse(
|
| 234 |
request,
|
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
/robots.txt and /sitemap.xml (doc 06, 2026-11-17).
|
| 3 |
+
|
| 4 |
+
/robots.txt used to be the HTML 404 page and there was no sitemap, so a search
|
| 5 |
+
engine had nothing to go on but links. Crawlers are kept off what is personal
|
| 6 |
+
or costly (search runs two models per query on 2 CPUs; /api/ is fragments)
|
| 7 |
+
and pointed at a few thousand pages worth finding: the public pages, every
|
| 8 |
+
collection, and the papers people actually look at here (this week's lists,
|
| 9 |
+
the papers Hacker News keeps returning to, collection papers, and papers that
|
| 10 |
+
already have a plain-language summary). Not all 2 million: a crawler working
|
| 11 |
+
through those would compete with readers for the same CPUs.
|
| 12 |
+
|
| 13 |
+
The sitemap is built in memory at most every SITEMAP_TTL_S and never fails:
|
| 14 |
+
a source that errors is left out.
|
| 15 |
+
"""
|
| 16 |
+
from __future__ import annotations
|
| 17 |
+
|
| 18 |
+
import time
|
| 19 |
+
from xml.sax.saxutils import escape
|
| 20 |
+
|
| 21 |
+
import aiosqlite
|
| 22 |
+
from fastapi import APIRouter
|
| 23 |
+
from fastapi.responses import PlainTextResponse, Response
|
| 24 |
+
|
| 25 |
+
from app import config, errors
|
| 26 |
+
|
| 27 |
+
router = APIRouter()
|
| 28 |
+
|
| 29 |
+
SITEMAP_MAX = 5000
|
| 30 |
+
SITEMAP_TTL_S = 6 * 3600
|
| 31 |
+
_cache: dict = {"at": 0.0, "body": ""}
|
| 32 |
+
|
| 33 |
+
ROBOTS = """User-agent: *
|
| 34 |
+
Disallow: /api/
|
| 35 |
+
Disallow: /search
|
| 36 |
+
Disallow: /saved
|
| 37 |
+
Disallow: /history
|
| 38 |
+
Disallow: /interests
|
| 39 |
+
Disallow: /onboarding
|
| 40 |
+
Disallow: /admin
|
| 41 |
+
Disallow: /healthz
|
| 42 |
+
Disallow: /l/
|
| 43 |
+
Disallow: /library/
|
| 44 |
+
Allow: /
|
| 45 |
+
|
| 46 |
+
Sitemap: {base}/sitemap.xml
|
| 47 |
+
"""
|
| 48 |
+
|
| 49 |
+
STATIC_PATHS = ("/", "/trending", "/trending/lasting", "/collections")
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
@router.get("/robots.txt", response_class=PlainTextResponse)
|
| 53 |
+
async def robots_txt() -> PlainTextResponse:
|
| 54 |
+
return PlainTextResponse(ROBOTS.format(base=config.PUBLIC_URL),
|
| 55 |
+
headers={"Cache-Control": "public, max-age=86400"})
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
async def _explained_ids(limit: int) -> list[str]:
|
| 59 |
+
async with aiosqlite.connect(config.DB_PATH) as conn:
|
| 60 |
+
rows = await (await conn.execute(
|
| 61 |
+
"SELECT arxiv_id FROM paper_explanations GROUP BY arxiv_id ORDER BY MAX(id) DESC LIMIT ?",
|
| 62 |
+
(limit,))).fetchall()
|
| 63 |
+
return [r[0] for r in rows]
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
async def paths() -> list[str]:
|
| 67 |
+
"""Every path in the sitemap, most important first, at most SITEMAP_MAX."""
|
| 68 |
+
from app import collections_svc, hn_svc, trending_shelf
|
| 69 |
+
out = list(STATIC_PATHS)
|
| 70 |
+
papers: list[str] = []
|
| 71 |
+
sources = (
|
| 72 |
+
("collections", lambda: [f"/collections/{c['slug']}" for c in collections_svc.load_all()]),
|
| 73 |
+
("trending", lambda: [p["arxiv_id"] for p in trending_shelf.week_top(200)]),
|
| 74 |
+
("lasting", lambda: [c["arxiv_id"] for c in hn_svc.lasting_cards()]),
|
| 75 |
+
("collection papers", lambda: [a for c in collections_svc.load_all()
|
| 76 |
+
for a in collections_svc.anchor_ids(c["slug"])]),
|
| 77 |
+
)
|
| 78 |
+
for name, get in sources:
|
| 79 |
+
try:
|
| 80 |
+
got = get()
|
| 81 |
+
except Exception as e:
|
| 82 |
+
errors.report("seo", f"sitemap source {name} failed", e)
|
| 83 |
+
continue
|
| 84 |
+
if name == "collections":
|
| 85 |
+
out += got
|
| 86 |
+
else:
|
| 87 |
+
papers += got
|
| 88 |
+
try:
|
| 89 |
+
papers += await _explained_ids(SITEMAP_MAX)
|
| 90 |
+
except Exception as e:
|
| 91 |
+
errors.report("seo", "sitemap source explained papers failed", e)
|
| 92 |
+
out += [f"/p/{a}" for a in dict.fromkeys(a for a in papers if a)]
|
| 93 |
+
return list(dict.fromkeys(out))[:SITEMAP_MAX]
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
@router.get("/sitemap.xml")
|
| 97 |
+
async def sitemap_xml() -> Response:
|
| 98 |
+
from app import trending_shelf
|
| 99 |
+
now = time.time()
|
| 100 |
+
body = _cache["body"]
|
| 101 |
+
if not body or now - _cache["at"] > SITEMAP_TTL_S:
|
| 102 |
+
urls = "".join(f"<url><loc>{escape(config.PUBLIC_URL + p)}</loc></url>" for p in await paths())
|
| 103 |
+
body = ('<?xml version="1.0" encoding="UTF-8"?>\n'
|
| 104 |
+
f'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">{urls}</urlset>\n')
|
| 105 |
+
# Just after a restart the week's lists are still loading: serve this
|
| 106 |
+
# one, but build again next time rather than keep it for hours.
|
| 107 |
+
if trending_shelf.week_top(1):
|
| 108 |
+
_cache.update(at=now, body=body)
|
| 109 |
+
return Response(body, media_type="application/xml",
|
| 110 |
+
headers={"Cache-Control": "public, max-age=3600"})
|
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
The front page a new visitor sees at / (doc 06, 2026-11-17).
|
| 3 |
+
|
| 4 |
+
Until now `/` sent everyone without a finished onboarding straight to the
|
| 5 |
+
two-step form: no product name, no search box, no paper. 8 of the first 18
|
| 6 |
+
outside readers never reached a feed. This page says what ResearchIT is,
|
| 7 |
+
offers search right away, and shows the week's most upvoted papers as real
|
| 8 |
+
cards a visitor can open or save. "Personalise your feed" leads to the same
|
| 9 |
+
onboarding as before, which is no longer the only way in.
|
| 10 |
+
|
| 11 |
+
A save from here counts like any other: the next visit to / finds the save,
|
| 12 |
+
marks onboarding done and serves a personal feed (one save is enough, §3.3).
|
| 13 |
+
The cards are a ranked surface, so they carry query_id, position, propensity
|
| 14 |
+
and policy_id and are written to the exposure log (§3.11).
|
| 15 |
+
"""
|
| 16 |
+
from __future__ import annotations
|
| 17 |
+
|
| 18 |
+
import uuid
|
| 19 |
+
|
| 20 |
+
from fastapi import Request
|
| 21 |
+
|
| 22 |
+
from app import card_data, db, errors, trending_shelf
|
| 23 |
+
from app.templates_env import corpus_label, templates
|
| 24 |
+
|
| 25 |
+
SOURCE = "welcome"
|
| 26 |
+
POLICY = "welcome_top_v1"
|
| 27 |
+
N_PAPERS = 7 # one wide lead card and two rows of three
|
| 28 |
+
EXAMPLES = (
|
| 29 |
+
"how do diffusion models generate images",
|
| 30 |
+
"LoRA fine-tuning",
|
| 31 |
+
"dark matter detection",
|
| 32 |
+
"protein structure prediction",
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
async def render(request: Request, user_id: str, started: bool):
|
| 37 |
+
"""The page itself. `started`: the visitor began onboarding and left it."""
|
| 38 |
+
papers = trending_shelf.week_top(N_PAPERS)
|
| 39 |
+
query_id = str(uuid.uuid4())
|
| 40 |
+
exposures = []
|
| 41 |
+
for i, p in enumerate(papers):
|
| 42 |
+
p.update(query_id=query_id, position=i, propensity=1.0, policy_id=POLICY,
|
| 43 |
+
ranker_version=POLICY, candidate_source=trending_shelf.CANDIDATE_SOURCE, cluster_id=None)
|
| 44 |
+
exposures.append({"user_id": user_id, "paper_id": p["arxiv_id"], "query_id": query_id,
|
| 45 |
+
"position": i, "tier": None, "candidate_source": p["candidate_source"],
|
| 46 |
+
"cluster_id": None, "propensity": 1.0, "policy_id": POLICY})
|
| 47 |
+
if exposures:
|
| 48 |
+
try:
|
| 49 |
+
await db.record_exposures(exposures)
|
| 50 |
+
except Exception as e: # pragma: no cover - analytics must not cost the page
|
| 51 |
+
errors.report("welcome", "exposure write failed", e)
|
| 52 |
+
await card_data.add_figures(papers, request)
|
| 53 |
+
return templates.TemplateResponse(request, "welcome.html", {
|
| 54 |
+
"papers": papers, "source": SOURCE, "query_id": query_id, "started": started,
|
| 55 |
+
"examples": EXAMPLES, "window": trending_shelf.window(),
|
| 56 |
+
"og_title": "ResearchIT",
|
| 57 |
+
"og_description": (f"Search {corpus_label()} arXiv papers in plain words, or get a reading feed that "
|
| 58 |
+
"learns your separate interests from the papers you save. Free, no sign-up."),
|
| 59 |
+
})
|
|
@@ -418,6 +418,23 @@
|
|
| 418 |
}
|
| 419 |
return;
|
| 420 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 421 |
var copy = target.closest && target.closest('[data-copy]');
|
| 422 |
if (copy) {
|
| 423 |
e.preventDefault();
|
|
|
|
| 418 |
}
|
| 419 |
return;
|
| 420 |
}
|
| 421 |
+
/* Share a paper: the phone's share sheet where there is one, else copy the link. */
|
| 422 |
+
var share = target.closest && target.closest('[data-share]');
|
| 423 |
+
if (share) {
|
| 424 |
+
e.preventDefault();
|
| 425 |
+
var url = share.getAttribute('data-share');
|
| 426 |
+
var copied = function () {
|
| 427 |
+
var t = makeToast('Link copied');
|
| 428 |
+
if (t) setTimeout(function () { closeToast(t); }, 2000);
|
| 429 |
+
};
|
| 430 |
+
if (navigator.share) {
|
| 431 |
+
navigator.share({ title: share.getAttribute('data-share-title') || 'ResearchIT', url: url })
|
| 432 |
+
.catch(function () {});
|
| 433 |
+
} else if (navigator.clipboard && navigator.clipboard.writeText) {
|
| 434 |
+
navigator.clipboard.writeText(url).then(copied, function () {});
|
| 435 |
+
}
|
| 436 |
+
return;
|
| 437 |
+
}
|
| 438 |
var copy = target.closest && target.closest('[data-copy]');
|
| 439 |
if (copy) {
|
| 440 |
e.preventDefault();
|
|
|
@@ -855,7 +855,11 @@ a.card-title:hover { color: var(--accent); }
|
|
| 855 |
.cat-grid--art { grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr)); }
|
| 856 |
.cat-grid--art .cat-opt { position: relative; padding: .45rem .45rem .7rem; }
|
| 857 |
.cat-grid--art .cat-opt .name,
|
| 858 |
-
.cat-grid--art .cat-opt .desc
|
|
|
|
|
|
|
|
|
|
|
|
|
| 859 |
.cat-opt .art {
|
| 860 |
display: block; margin-bottom: .45rem; border-radius: 4px;
|
| 861 |
background: var(--surface-2); transition: background .12s ease;
|
|
@@ -2159,9 +2163,10 @@ a.src:hover { text-decoration: underline; }
|
|
| 2159 |
.topic-row--steady .topic-delta { color: var(--text-2); }
|
| 2160 |
.topic-row--steady .topic-spark polyline { stroke: var(--text-3); }
|
| 2161 |
|
| 2162 |
-
.library-tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: .4rem; }
|
| 2163 |
.library-tab { font-size: .88rem; font-weight: 600; color: var(--text-3); text-decoration: none;
|
| 2164 |
padding: .45rem .75rem; border-bottom: 2px solid transparent; margin-bottom: -1px; }
|
|
|
|
| 2165 |
.library-tab:hover { color: var(--text); }
|
| 2166 |
.library-tab[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); }
|
| 2167 |
.library-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
|
@@ -2377,3 +2382,67 @@ a.src:hover { text-decoration: underline; }
|
|
| 2377 |
.hn-row--norank { grid-template-columns: minmax(0, 1fr); }
|
| 2378 |
.hn-row--norank .hn-row-actions { grid-column: 1; }
|
| 2379 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 855 |
.cat-grid--art { grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr)); }
|
| 856 |
.cat-grid--art .cat-opt { position: relative; padding: .45rem .45rem .7rem; }
|
| 857 |
.cat-grid--art .cat-opt .name,
|
| 858 |
+
.cat-grid--art .cat-opt .desc,
|
| 859 |
+
.cat-grid--art .cat-opt .cov { padding-inline: .3rem; }
|
| 860 |
+
/* Areas the corpus holds only in part before mid-2025 (config.AREA_COVERAGE_NOTES). */
|
| 861 |
+
.cat-opt .cov { margin-top: .15rem; font-family: var(--font-mono); font-size: .64rem; line-height: 1.35; color: var(--text-3); }
|
| 862 |
+
.cat-opt .cov::before { content: "◐ "; color: var(--info); }
|
| 863 |
.cat-opt .art {
|
| 864 |
display: block; margin-bottom: .45rem; border-radius: 4px;
|
| 865 |
background: var(--surface-2); transition: background .12s ease;
|
|
|
|
| 2163 |
.topic-row--steady .topic-delta { color: var(--text-2); }
|
| 2164 |
.topic-row--steady .topic-spark polyline { stroke: var(--text-3); }
|
| 2165 |
|
| 2166 |
+
.library-tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: .4rem; overflow-x: auto; scrollbar-width: none; }
|
| 2167 |
.library-tab { font-size: .88rem; font-weight: 600; color: var(--text-3); text-decoration: none;
|
| 2168 |
padding: .45rem .75rem; border-bottom: 2px solid transparent; margin-bottom: -1px; }
|
| 2169 |
+
.library-tab { white-space: nowrap; flex: none; }
|
| 2170 |
.library-tab:hover { color: var(--text); }
|
| 2171 |
.library-tab[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); }
|
| 2172 |
.library-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
|
|
|
| 2382 |
.hn-row--norank { grid-template-columns: minmax(0, 1fr); }
|
| 2383 |
.hn-row--norank .hn-row-actions { grid-column: 1; }
|
| 2384 |
}
|
| 2385 |
+
|
| 2386 |
+
/* ── Front page for new visitors (welcome.html; doc 06, 2026-11-17) ───────────
|
| 2387 |
+
Says what ResearchIT is, takes a search with no setup, and shows the week's
|
| 2388 |
+
papers as real cards. Beside the hero on wide screens, how the feed works. */
|
| 2389 |
+
.welcome { display: flex; flex-direction: column; gap: 2.2rem; }
|
| 2390 |
+
.wl-top { display: grid; gap: 1.6rem; align-items: start; padding-top: clamp(.5rem, 3vh, 2rem); }
|
| 2391 |
+
@media (min-width: 900px) { .wl-top { grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); gap: 3rem; } }
|
| 2392 |
+
.wl-hero { display: flex; flex-direction: column; gap: .9rem; min-width: 0; }
|
| 2393 |
+
.wl-kicker { margin: 0; font-family: var(--font-mono); font-size: .7rem; font-weight: 600; letter-spacing: .12em;
|
| 2394 |
+
text-transform: uppercase; color: var(--accent); }
|
| 2395 |
+
.wl-title { margin: 0; font-family: var(--font-read); font-weight: 700; letter-spacing: -.015em;
|
| 2396 |
+
font-size: clamp(2rem, 5.2vw, 3.1rem); line-height: 1.08; text-wrap: balance; }
|
| 2397 |
+
.wl-lede { margin: 0; max-width: 36rem; font-family: var(--font-read); font-size: 1.08rem; line-height: 1.55; color: var(--text-2); }
|
| 2398 |
+
.wl-search { margin-top: .4rem; padding: .45rem .45rem .45rem 1rem; }
|
| 2399 |
+
.wl-search input { font-size: 1.05rem; }
|
| 2400 |
+
.wl-try { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: .35rem .45rem; font-size: .8rem; }
|
| 2401 |
+
.wl-try span { font-family: var(--font-mono); font-size: .66rem; letter-spacing: .1em; text-transform: uppercase; color: var(--text-3); }
|
| 2402 |
+
.wl-try a { color: var(--text-2); text-decoration: none; border: 1px solid var(--border); background: var(--surface);
|
| 2403 |
+
border-radius: 99px; padding: .2rem .65rem; }
|
| 2404 |
+
.wl-try a:hover { border-color: var(--accent); color: var(--accent); }
|
| 2405 |
+
.wl-cta { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem 1rem; margin-top: .5rem; }
|
| 2406 |
+
.wl-how--after { display: none; }
|
| 2407 |
+
@media (max-width: 899px) { .wl-how--beside { display: none; } .wl-how--after { display: block; } }
|
| 2408 |
+
.wl-how { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
|
| 2409 |
+
padding: 1.1rem 1.2rem 1.2rem; box-shadow: var(--shadow-1); }
|
| 2410 |
+
.wl-how-h { margin: 0 0 .8rem; font-family: var(--font-read); font-size: 1.05rem; font-weight: 650; }
|
| 2411 |
+
.wl-steps { list-style: none; margin: 0; padding: 0; counter-reset: wl; display: flex; flex-direction: column; gap: .9rem; }
|
| 2412 |
+
.wl-steps li { counter-increment: wl; display: grid; grid-template-columns: 1.9rem minmax(0, 1fr); column-gap: .6rem; }
|
| 2413 |
+
.wl-steps li::before { content: counter(wl); grid-row: span 2; width: 1.6rem; height: 1.6rem; border-radius: 50%;
|
| 2414 |
+
display: grid; place-items: center; font-family: var(--font-mono); font-size: .75rem; font-weight: 700;
|
| 2415 |
+
color: var(--accent); background: var(--accent-bg); border: 1px solid var(--accent-br); }
|
| 2416 |
+
.wl-steps b { font-size: .92rem; font-weight: 600; }
|
| 2417 |
+
.wl-steps span { font-size: .84rem; line-height: 1.45; color: var(--text-2); }
|
| 2418 |
+
.wl-week .shelf-more { margin-left: auto; }
|
| 2419 |
+
.wl-foot { margin: 0; text-align: center; }
|
| 2420 |
+
|
| 2421 |
+
/* A search with no close match (config.SEARCH_WEAK_MATCH; doc 06, 2026-11-17). */
|
| 2422 |
+
.weak-match { border: 1px solid var(--border-2); border-left: 3px solid var(--info); border-radius: var(--radius-sm);
|
| 2423 |
+
background: var(--info-bg); padding: .75rem .95rem; font-size: .88rem; line-height: 1.5; color: var(--text-2); }
|
| 2424 |
+
.weak-match p { margin: 0; }
|
| 2425 |
+
.weak-match-h { font-weight: 600; color: var(--text) !important; margin-bottom: .2rem !important; }
|
| 2426 |
+
|
| 2427 |
+
/* Library > Other devices, and opening a library link (app/routers/library.py). */
|
| 2428 |
+
.devlink { display: flex; flex-direction: column; gap: .8rem; padding-top: 1.2rem; max-width: 40rem; }
|
| 2429 |
+
.devlink--open { padding-top: clamp(1rem, 6vh, 3rem); }
|
| 2430 |
+
.devlink-h { margin: 0; font-family: var(--font-read); font-size: 1.2rem; }
|
| 2431 |
+
.devlink-h3 { margin: .8rem 0 0; font-family: var(--font-read); font-size: 1rem; }
|
| 2432 |
+
.devlink-p { margin: 0; line-height: 1.55; color: var(--text-2); }
|
| 2433 |
+
.devlink-box { display: flex; flex-wrap: wrap; gap: .45rem; align-items: center; scroll-margin-top: 5rem; }
|
| 2434 |
+
.devlink-url { flex: 1 1 16rem; min-width: 0; font-family: var(--font-mono); font-size: .82rem; padding: .55rem .7rem;
|
| 2435 |
+
border: 1px solid var(--border-2); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); }
|
| 2436 |
+
.devlink-note { margin: 0; font-size: .8rem; line-height: 1.5; color: var(--text-3); }
|
| 2437 |
+
.devlink-actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
|
| 2438 |
+
.devlink-actions form { margin: 0; }
|
| 2439 |
+
.devlink-steps { margin: 0; padding-left: 1.2rem; display: flex; flex-direction: column; gap: .3rem; font-size: .88rem; color: var(--text-2); }
|
| 2440 |
+
.lib-notice { margin: 0; padding: .6rem .85rem; border-radius: var(--radius-sm); background: var(--accent-bg);
|
| 2441 |
+
border: 1px solid var(--accent-br); color: var(--text); font-size: .88rem; }
|
| 2442 |
+
/* Onboarding's way back to the front page: the form is no longer the only way in. */
|
| 2443 |
+
.ob-back { display: inline-block; margin-bottom: 1rem; font-size: .82rem; color: var(--text-3); text-decoration: none; }
|
| 2444 |
+
.ob-back:hover { color: var(--accent); }
|
| 2445 |
+
.weak-match a { color: var(--accent); }
|
| 2446 |
+
/* Share on the paper page: a button that reads like the PDF link beside it. */
|
| 2447 |
+
.lnk-btn { background: none; border: 0; font: inherit; cursor: pointer; text-decoration: none; }
|
| 2448 |
+
.inline-acts .lnk-btn:hover { color: var(--accent); }
|
|
@@ -34,18 +34,32 @@
|
|
| 34 |
no description — which for a product whose growth loop is people sharing
|
| 35 |
papers is the cheapest win available.
|
| 36 |
|
| 37 |
-
|
| 38 |
-
a broken image reference is worse than a card with none. summary_large_image
|
| 39 |
-
would be the card type to switch to once that exists.
|
| 40 |
#}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
<meta property="og:site_name" content="ResearchIT" />
|
| 42 |
<meta property="og:type" content="{{ og_type | default('website') }}" />
|
| 43 |
<meta property="og:title" content="{{ _og_title }}" />
|
| 44 |
<meta property="og:description" content="{{ _og_description }}" />
|
| 45 |
-
|
| 46 |
-
<meta
|
|
|
|
| 47 |
<meta name="twitter:title" content="{{ _og_title }}" />
|
| 48 |
<meta name="twitter:description" content="{{ _og_description }}" />
|
|
|
|
| 49 |
|
| 50 |
<link rel="stylesheet" href="/static/styles.css?v={{ static_version }}" />
|
| 51 |
|
|
|
|
| 34 |
no description — which for a product whose growth loop is people sharing
|
| 35 |
papers is the cheapest win available.
|
| 36 |
|
| 37 |
+
The image is a real asset (app/static/og.png) or a paper's own figure.
|
|
|
|
|
|
|
| 38 |
#}
|
| 39 |
+
{#
|
| 40 |
+
Links that leave the site are built from config.PUBLIC_URL: behind the
|
| 41 |
+
Space's proxy request.url says http://. The picture is the paper's first
|
| 42 |
+
figure when the page passes one (og_image), else app/static/og.png
|
| 43 |
+
(scripts/build_og_image.py). Personal pages and search results are not
|
| 44 |
+
for search engines (see also /robots.txt).
|
| 45 |
+
#}
|
| 46 |
+
{% set _path = request.url.path if request else '/' %}
|
| 47 |
+
{% set _og_image = og_image | default(public_url ~ "/static/og.png") %}
|
| 48 |
+
{% if _path.startswith(('/search', '/saved', '/history', '/interests', '/library', '/l/', '/admin', '/onboarding')) %}
|
| 49 |
+
<meta name="robots" content="noindex" />
|
| 50 |
+
{% else %}
|
| 51 |
+
<link rel="canonical" href="{{ public_url }}{{ _path }}" />
|
| 52 |
+
{% endif %}
|
| 53 |
<meta property="og:site_name" content="ResearchIT" />
|
| 54 |
<meta property="og:type" content="{{ og_type | default('website') }}" />
|
| 55 |
<meta property="og:title" content="{{ _og_title }}" />
|
| 56 |
<meta property="og:description" content="{{ _og_description }}" />
|
| 57 |
+
<meta property="og:url" content="{{ public_url }}{{ _path }}" />
|
| 58 |
+
<meta property="og:image" content="{{ _og_image }}" />
|
| 59 |
+
<meta name="twitter:card" content="summary_large_image" />
|
| 60 |
<meta name="twitter:title" content="{{ _og_title }}" />
|
| 61 |
<meta name="twitter:description" content="{{ _og_description }}" />
|
| 62 |
+
<meta name="twitter:image" content="{{ _og_image }}" />
|
| 63 |
|
| 64 |
<link rel="stylesheet" href="/static/styles.css?v={{ static_version }}" />
|
| 65 |
|
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends "base.html" %}
|
| 2 |
+
|
| 3 |
+
{#
|
| 4 |
+
Library > Other devices (app/routers/library.py). One private link that
|
| 5 |
+
opens this library in any browser: Copy, Share (phones), make a new one, or
|
| 6 |
+
turn it off. The link is shown in full so it can be checked before sending.
|
| 7 |
+
#}
|
| 8 |
+
|
| 9 |
+
{% block title %}Other devices — ResearchIT{% endblock %}
|
| 10 |
+
|
| 11 |
+
{% block content %}
|
| 12 |
+
<div class="wrap wrap--feed">
|
| 13 |
+
<header class="issue">
|
| 14 |
+
<div class="issue-kicker">Your collection</div>
|
| 15 |
+
<h1 class="issue-title">Library</h1>
|
| 16 |
+
<div class="issue-line"><span>Use it on your phone, laptop or another browser</span></div>
|
| 17 |
+
</header>
|
| 18 |
+
{% include "partials/library_tabs.html" %}
|
| 19 |
+
|
| 20 |
+
<section class="devlink" aria-labelledby="devlink-h">
|
| 21 |
+
<h2 id="devlink-h" class="devlink-h">Your library link</h2>
|
| 22 |
+
<p class="devlink-p">ResearchIT has no accounts. Your {{ count }} saved paper{{ "s" if count != 1 }}, your interests and the
|
| 23 |
+
collections you follow live in this browser. Open this link anywhere else and the same library opens there.</p>
|
| 24 |
+
|
| 25 |
+
{% if link %}
|
| 26 |
+
<div class="devlink-box" id="link">
|
| 27 |
+
<input type="text" class="devlink-url" id="devlink-url" value="{{ link }}" readonly
|
| 28 |
+
aria-label="Your library link" onclick="this.select()" />
|
| 29 |
+
<button type="button" class="btn btn-primary btn-sm" id="devlink-copy">Copy</button>
|
| 30 |
+
<button type="button" class="btn btn-quiet btn-sm" id="devlink-share" hidden>Share</button>
|
| 31 |
+
</div>
|
| 32 |
+
<p class="devlink-note" id="devlink-status" role="status" aria-live="polite">Treat it like a key: anyone with this link sees and changes your library.
|
| 33 |
+
Send it only to yourself, for example to your own email or notes.</p>
|
| 34 |
+
<div class="devlink-actions">
|
| 35 |
+
<form method="post" action="/api/library-link">
|
| 36 |
+
<button type="submit" class="btn btn-quiet btn-sm">Make a new link</button>
|
| 37 |
+
</form>
|
| 38 |
+
<form method="post" action="/api/library-link/revoke">
|
| 39 |
+
<button type="submit" class="btn btn-ghost btn-sm">Turn the link off</button>
|
| 40 |
+
</form>
|
| 41 |
+
</div>
|
| 42 |
+
<p class="devlink-note">A new link replaces this one, and this one stops working.</p>
|
| 43 |
+
{% else %}
|
| 44 |
+
<form method="post" action="/api/library-link" class="devlink-actions">
|
| 45 |
+
<button type="submit" class="btn btn-primary btn-sm">Make my library link</button>
|
| 46 |
+
</form>
|
| 47 |
+
<p class="devlink-note">You can replace it or turn it off here at any time.</p>
|
| 48 |
+
{% endif %}
|
| 49 |
+
|
| 50 |
+
<h3 class="devlink-h3">On the other device</h3>
|
| 51 |
+
<ol class="devlink-steps">
|
| 52 |
+
<li>Open the link in the browser you want to use.</li>
|
| 53 |
+
<li>If that browser has saved papers of its own, ResearchIT asks first, then adds them to this library.</li>
|
| 54 |
+
<li>From then on both browsers show the same library and the same feed.</li>
|
| 55 |
+
</ol>
|
| 56 |
+
</section>
|
| 57 |
+
</div>
|
| 58 |
+
{% endblock %}
|
| 59 |
+
|
| 60 |
+
{% block scripts %}
|
| 61 |
+
<script>
|
| 62 |
+
(function () {
|
| 63 |
+
var input = document.getElementById('devlink-url');
|
| 64 |
+
if (!input) return;
|
| 65 |
+
var status = document.getElementById('devlink-status');
|
| 66 |
+
document.getElementById('devlink-copy').addEventListener('click', function () {
|
| 67 |
+
var btn = this;
|
| 68 |
+
function done() { btn.textContent = 'Copied'; setTimeout(function () { btn.textContent = 'Copy'; }, 1600); }
|
| 69 |
+
function fallback() { input.focus(); input.select(); status.textContent = 'Selected. Press Ctrl+C or ⌘C to copy.'; }
|
| 70 |
+
try { navigator.clipboard.writeText(input.value).then(done, fallback); } catch (e) { fallback(); }
|
| 71 |
+
});
|
| 72 |
+
var share = document.getElementById('devlink-share');
|
| 73 |
+
if (navigator.share) {
|
| 74 |
+
share.hidden = false;
|
| 75 |
+
share.addEventListener('click', function () {
|
| 76 |
+
navigator.share({ title: 'My ResearchIT library', url: input.value }).catch(function () {});
|
| 77 |
+
});
|
| 78 |
+
}
|
| 79 |
+
})();
|
| 80 |
+
</script>
|
| 81 |
+
{% endblock %}
|
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends "base.html" %}
|
| 2 |
+
|
| 3 |
+
{#
|
| 4 |
+
Opening a library link (app/routers/library.py, GET /l/{token}).
|
| 5 |
+
state "confirm": this browser has saves of its own, so ask before switching.
|
| 6 |
+
state "gone": the link was replaced, turned off or never existed.
|
| 7 |
+
#}
|
| 8 |
+
|
| 9 |
+
{% block title %}{{ "Open this library?" if state == "confirm" else "Link no longer works" }} — ResearchIT{% endblock %}
|
| 10 |
+
|
| 11 |
+
{% block content %}
|
| 12 |
+
<div class="wrap wrap--feed">
|
| 13 |
+
<section class="devlink devlink--open">
|
| 14 |
+
{% if state == "confirm" %}
|
| 15 |
+
<div class="issue-kicker">Library link</div>
|
| 16 |
+
<h1 class="issue-title">Open this library here?</h1>
|
| 17 |
+
<p class="devlink-p">This browser already has its own library with <b>{{ mine }}</b> saved paper{{ "s" if mine != 1 }}.
|
| 18 |
+
The link opens a library with <b>{{ theirs }}</b> saved paper{{ "s" if theirs != 1 }}. If you open it, this browser's saved papers and followed
|
| 19 |
+
collections are added to it, and this browser shows that library from now on.</p>
|
| 20 |
+
<p class="devlink-note">Only open library links you made yourself. Anyone with the link sees that library.</p>
|
| 21 |
+
<div class="devlink-actions">
|
| 22 |
+
<form method="post" action="/l/{{ token }}">
|
| 23 |
+
<button type="submit" class="btn btn-primary">Open it and add my {{ mine }} paper{{ "s" if mine != 1 }}</button>
|
| 24 |
+
</form>
|
| 25 |
+
<a class="btn btn-ghost" href="/saved">Keep this browser's library</a>
|
| 26 |
+
</div>
|
| 27 |
+
{% else %}
|
| 28 |
+
<div class="issue-kicker">Library link</div>
|
| 29 |
+
<h1 class="issue-title">This link no longer works</h1>
|
| 30 |
+
<p class="devlink-p">Its owner made a new link or turned it off. On the device where the library is, open
|
| 31 |
+
Library, then Other devices, to get the current link.</p>
|
| 32 |
+
<div class="devlink-actions"><a class="btn btn-primary" href="/">Go to ResearchIT</a></div>
|
| 33 |
+
{% endif %}
|
| 34 |
+
</section>
|
| 35 |
+
</div>
|
| 36 |
+
{% endblock %}
|
|
@@ -24,6 +24,7 @@
|
|
| 24 |
<body>
|
| 25 |
<main class="wrap" style="max-width:46rem;padding-block:clamp(2rem,7vh,4.5rem) 8rem">
|
| 26 |
|
|
|
|
| 27 |
<div id="step-1" class="ob-step">
|
| 28 |
<div class="ob-progress">
|
| 29 |
<span>Step 1 of 2</span>
|
|
@@ -70,6 +71,7 @@
|
|
| 70 |
<span class="cat-tick" aria-hidden="true"><svg viewBox="0 0 16 16"><path d="M3.5 8.5 6.5 11.5 12.5 4.5"/></svg></span>
|
| 71 |
<span class="name">{{ cat.name }}</span>
|
| 72 |
<span class="desc">{{ cat.desc }}</span>
|
|
|
|
| 73 |
</button>
|
| 74 |
{% endfor %}
|
| 75 |
</div>
|
|
|
|
| 24 |
<body>
|
| 25 |
<main class="wrap" style="max-width:46rem;padding-block:clamp(2rem,7vh,4.5rem) 8rem">
|
| 26 |
|
| 27 |
+
<a href="/" class="ob-back">← ResearchIT</a>
|
| 28 |
<div id="step-1" class="ob-step">
|
| 29 |
<div class="ob-progress">
|
| 30 |
<span>Step 1 of 2</span>
|
|
|
|
| 71 |
<span class="cat-tick" aria-hidden="true"><svg viewBox="0 0 16 16"><path d="M3.5 8.5 6.5 11.5 12.5 4.5"/></svg></span>
|
| 72 |
<span class="name">{{ cat.name }}</span>
|
| 73 |
<span class="desc">{{ cat.desc }}</span>
|
| 74 |
+
{% if coverage.get(key) %}<span class="cov">{{ coverage[key] }}</span>{% endif %}
|
| 75 |
</button>
|
| 76 |
{% endfor %}
|
| 77 |
</div>
|
|
@@ -87,6 +87,9 @@
|
|
| 87 |
</div>
|
| 88 |
<span class="code-slot" data-quiet hx-get="/api/papers/{{ pid }}/code" hx-trigger="load" hx-swap="outerHTML"></span>
|
| 89 |
<a class="lnk" href="https://arxiv.org/pdf/{{ pid }}" target="_blank" rel="noopener">PDF ↗</a>
|
|
|
|
|
|
|
|
|
|
| 90 |
<div class="pc-menu">
|
| 91 |
<button type="button" class="pc-menu-btn" data-menu aria-haspopup="true" aria-expanded="false"
|
| 92 |
aria-label="More about this paper">
|
|
|
|
| 87 |
</div>
|
| 88 |
<span class="code-slot" data-quiet hx-get="/api/papers/{{ pid }}/code" hx-trigger="load" hx-swap="outerHTML"></span>
|
| 89 |
<a class="lnk" href="https://arxiv.org/pdf/{{ pid }}" target="_blank" rel="noopener">PDF ↗</a>
|
| 90 |
+
{#- The link previews with the paper's figure (base.html og:image). -#}
|
| 91 |
+
<button type="button" class="lnk lnk-btn" data-share="{{ public_url }}/p/{{ pid }}"
|
| 92 |
+
data-share-title="{{ paper.title }}">Share</button>
|
| 93 |
<div class="pc-menu">
|
| 94 |
<button type="button" class="pc-menu-btn" data-menu aria-haspopup="true" aria-expanded="false"
|
| 95 |
aria-label="More about this paper">
|
|
@@ -1,5 +1,5 @@
|
|
| 1 |
{#
|
| 2 |
-
Library's own tabs: Saved, Collections, Recent. Collections moved here when
|
| 3 |
Trending took its place in the main bar (doc 06, 2026-10-25); without the
|
| 4 |
Trending tab, Collections is in the main bar and this shows Saved and Recent.
|
| 5 |
Expects `library_tab` ("saved", "collections" or "recent").
|
|
@@ -9,4 +9,5 @@
|
|
| 9 |
<a href="/saved" class="library-tab" {% if library_tab == "saved" %}aria-current="page"{% endif %}>Saved</a>
|
| 10 |
{% if trending_tab %}<a href="/collections" class="library-tab" {% if library_tab == "collections" %}aria-current="page"{% endif %}>Collections</a>{% endif %}
|
| 11 |
<a href="/history" class="library-tab" {% if library_tab == "recent" %}aria-current="page"{% endif %}>Recent</a>
|
|
|
|
| 12 |
</nav>
|
|
|
|
| 1 |
{#
|
| 2 |
+
Library's own tabs: Saved, Collections, Recent, Other devices (library links). Collections moved here when
|
| 3 |
Trending took its place in the main bar (doc 06, 2026-10-25); without the
|
| 4 |
Trending tab, Collections is in the main bar and this shows Saved and Recent.
|
| 5 |
Expects `library_tab` ("saved", "collections" or "recent").
|
|
|
|
| 9 |
<a href="/saved" class="library-tab" {% if library_tab == "saved" %}aria-current="page"{% endif %}>Saved</a>
|
| 10 |
{% if trending_tab %}<a href="/collections" class="library-tab" {% if library_tab == "collections" %}aria-current="page"{% endif %}>Collections</a>{% endif %}
|
| 11 |
<a href="/history" class="library-tab" {% if library_tab == "recent" %}aria-current="page"{% endif %}>Recent</a>
|
| 12 |
+
<a href="/library/devices" class="library-tab" {% if library_tab == "devices" %}aria-current="page"{% endif %}>Other devices</a>
|
| 13 |
</nav>
|
|
@@ -51,7 +51,16 @@
|
|
| 51 |
<p class="small muted" role="status">Showing keyword matches. Semantic matches are unavailable for this search.</p>
|
| 52 |
{% endif %}
|
| 53 |
|
| 54 |
-
{% if
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
{% set arxiv_ids = papers | map(attribute='arxiv_id') | join(',') %}
|
| 56 |
<div id="ai-summary-container"
|
| 57 |
hx-get="/api/search/summary?q={{ query | urlencode }}&ids={{ arxiv_ids }}{% if papers[0].query_id %}&qid={{ papers[0].query_id }}{% endif %}"
|
|
|
|
| 51 |
<p class="small muted" role="status">Showing keyword matches. Semantic matches are unavailable for this search.</p>
|
| 52 |
{% endif %}
|
| 53 |
|
| 54 |
+
{% if weak_match %}
|
| 55 |
+
<div class="weak-match" role="status">
|
| 56 |
+
<p class="weak-match-h">None of these is a close match.</p>
|
| 57 |
+
<p>ResearchIT searches {{ corpus_label() }} research papers on arXiv. These are the nearest it found.
|
| 58 |
+
For research on this, try naming a method, a field or a question, like
|
| 59 |
+
<a href="/search?q={{ ('how do recommender systems rank items') | urlencode }}">how do recommender systems rank items</a>.</p>
|
| 60 |
+
</div>
|
| 61 |
+
{% endif %}
|
| 62 |
+
|
| 63 |
+
{% if query and papers and not weak_match %}
|
| 64 |
{% set arxiv_ids = papers | map(attribute='arxiv_id') | join(',') %}
|
| 65 |
<div id="ai-summary-container"
|
| 66 |
hx-get="/api/search/summary?q={{ query | urlencode }}&ids={{ arxiv_ids }}{% if papers[0].query_id %}&qid={{ papers[0].query_id }}{% endif %}"
|
|
@@ -16,13 +16,18 @@
|
|
| 16 |
<h1 class="issue-title">Library</h1>
|
| 17 |
<div class="issue-line">
|
| 18 |
<span><b>{{ count }}</b> paper{{ "s" if count != 1 }} saved</span>
|
| 19 |
-
{% if count
|
| 20 |
<span class="sep">·</span>
|
| 21 |
-
<span>
|
| 22 |
{% endif %}
|
| 23 |
</div>
|
| 24 |
</header>
|
| 25 |
{% set library_tab = "saved" %}{% include "partials/library_tabs.html" %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
{% if count > 0 %}
|
| 28 |
<div class="feed">
|
|
@@ -36,8 +41,8 @@
|
|
| 36 |
<div class="empty">
|
| 37 |
<p class="empty-title">Nothing saved yet</p>
|
| 38 |
<p class="empty-body">
|
| 39 |
-
Papers you save are what the feed learns from
|
| 40 |
-
|
| 41 |
</p>
|
| 42 |
<div style="padding-top:.4rem">
|
| 43 |
<a href="/search" class="btn btn-primary btn-sm">Find papers</a>
|
|
|
|
| 16 |
<h1 class="issue-title">Library</h1>
|
| 17 |
<div class="issue-line">
|
| 18 |
<span><b>{{ count }}</b> paper{{ "s" if count != 1 }} saved</span>
|
| 19 |
+
{% if count %}
|
| 20 |
<span class="sep">·</span>
|
| 21 |
+
<span>each one shapes your feed</span>
|
| 22 |
{% endif %}
|
| 23 |
</div>
|
| 24 |
</header>
|
| 25 |
{% set library_tab = "saved" %}{% include "partials/library_tabs.html" %}
|
| 26 |
+
{% if opened == "1" %}
|
| 27 |
+
<p class="lib-notice" role="status">Your library is open in this browser.{% if added %} {{ added }} paper{{ "s" if added != 1 }} saved here before {{ "were" if added != 1 else "was" }} added to it.{% endif %}</p>
|
| 28 |
+
{% elif opened == "here" %}
|
| 29 |
+
<p class="lib-notice" role="status">That link is for this library, and it is already open here.</p>
|
| 30 |
+
{% endif %}
|
| 31 |
|
| 32 |
{% if count > 0 %}
|
| 33 |
<div class="feed">
|
|
|
|
| 41 |
<div class="empty">
|
| 42 |
<p class="empty-title">Nothing saved yet</p>
|
| 43 |
<p class="empty-body">
|
| 44 |
+
Papers you save are what the feed learns from. One save is enough to
|
| 45 |
+
start a personal feed, and every save after sharpens it.
|
| 46 |
</p>
|
| 47 |
<div style="padding-top:.4rem">
|
| 48 |
<a href="/search" class="btn btn-primary btn-sm">Find papers</a>
|
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends "base.html" %}
|
| 2 |
+
|
| 3 |
+
{#
|
| 4 |
+
The front page for a visitor without a finished onboarding (app/routers/
|
| 5 |
+
welcome.py; doc 06, 2026-11-17). It used to be a redirect to the form.
|
| 6 |
+
Search works from here with no setup; the week's papers are real cards a
|
| 7 |
+
visitor can open or save; "Personalise your feed" leads to onboarding.
|
| 8 |
+
#}
|
| 9 |
+
|
| 10 |
+
{% block title %}ResearchIT — papers picked for what you work on{% endblock %}
|
| 11 |
+
|
| 12 |
+
{#- Beside the hero on wide screens; after the papers on a phone, so the
|
| 13 |
+
first screen reaches a paper sooner. -#}
|
| 14 |
+
{% macro how(where) %}
|
| 15 |
+
<aside class="wl-how{{ where }}" aria-label="How the feed works">
|
| 16 |
+
<h2 class="wl-how-h">How the feed works</h2>
|
| 17 |
+
<ol class="wl-steps">
|
| 18 |
+
<li><b>Tell it your areas</b><span>Pick them, or describe your work and it suggests them.</span></li>
|
| 19 |
+
<li><b>Save what you like</b><span>One save is enough to start. It finds your separate interests and gives each its share of the page.</span></li>
|
| 20 |
+
<li><b>Read faster</b><span>Each paper opens with a plain-language summary, its figures, and answers to your questions about it.</span></li>
|
| 21 |
+
</ol>
|
| 22 |
+
</aside>
|
| 23 |
+
{% endmacro %}
|
| 24 |
+
|
| 25 |
+
{% block content %}
|
| 26 |
+
<div class="wrap wrap--trend welcome">
|
| 27 |
+
|
| 28 |
+
<section class="wl-top">
|
| 29 |
+
<div class="wl-hero">
|
| 30 |
+
<p class="wl-kicker">{{ corpus_label() }} arXiv papers · free · no sign-up</p>
|
| 31 |
+
<h1 class="wl-title">Find the papers that matter to your work.</h1>
|
| 32 |
+
<p class="wl-lede">Search in plain words, or let a reading feed learn what you work on from the papers you save.
|
| 33 |
+
Each of your interests keeps its own share, so a side topic never gets drowned out.</p>
|
| 34 |
+
|
| 35 |
+
<form class="searchbar wl-search" action="/search" method="get" role="search">
|
| 36 |
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9"
|
| 37 |
+
stroke-linecap="round" aria-hidden="true">
|
| 38 |
+
<circle cx="11" cy="11" r="7" /><path d="m21 21-4.3-4.3" />
|
| 39 |
+
</svg>
|
| 40 |
+
<input type="search" name="q" id="welcome-q" placeholder="A topic or a question"
|
| 41 |
+
aria-label="Search papers" autocomplete="off" required />
|
| 42 |
+
<button class="btn btn-primary btn-sm" type="submit">Search</button>
|
| 43 |
+
</form>
|
| 44 |
+
<p class="wl-try"><span>Try</span>
|
| 45 |
+
{% for q in examples %}<a href="/search?q={{ q | urlencode }}">{{ q }}</a>{% endfor %}
|
| 46 |
+
</p>
|
| 47 |
+
|
| 48 |
+
<div class="wl-cta">
|
| 49 |
+
<a class="btn btn-primary" href="/onboarding">{{ "Finish setting up your feed" if started else "Personalise your feed" }}</a>
|
| 50 |
+
<span class="small muted">About a minute: pick areas, or describe your work in a sentence.</span>
|
| 51 |
+
</div>
|
| 52 |
+
</div>
|
| 53 |
+
|
| 54 |
+
{{ how(" wl-how--beside") }}
|
| 55 |
+
</section>
|
| 56 |
+
|
| 57 |
+
{% if papers %}
|
| 58 |
+
<section class="shelf wl-week" aria-labelledby="wl-week-h">
|
| 59 |
+
<header class="shelf-head">
|
| 60 |
+
<h2 class="shelf-title" id="wl-week-h">Most upvoted this week</h2>
|
| 61 |
+
<span class="shelf-note">From Hugging Face Daily Papers{% if window %}, {{ window.label }}{% endif %}. Save one and your feed starts from it.</span>
|
| 62 |
+
{% if feature_visible("TRENDING_PAGE", request) %}<a class="shelf-more" href="/trending">All of this week →</a>{% endif %}
|
| 63 |
+
</header>
|
| 64 |
+
<ol class="tgrid tgrid--top">
|
| 65 |
+
{% for paper in papers %}{% set lead = loop.first %}{% include "partials/trending_card.html" %}{% endfor %}
|
| 66 |
+
</ol>
|
| 67 |
+
</section>
|
| 68 |
+
{% endif %}
|
| 69 |
+
|
| 70 |
+
{{ how(" wl-how--after") }}
|
| 71 |
+
|
| 72 |
+
<p class="wl-foot small muted">Already use ResearchIT on another device? Open your library link here.
|
| 73 |
+
You'll find it under Library, in Other devices.</p>
|
| 74 |
+
</div>
|
| 75 |
+
{% endblock %}
|
|
@@ -288,6 +288,7 @@ templates.env.filters["is_truncated"] = _is_truncated
|
|
| 288 |
from app import config # noqa: E402 (after `templates` exists, avoids a cycle)
|
| 289 |
|
| 290 |
templates.env.globals["space_app_url"] = config.SPACE_APP_URL
|
|
|
|
| 291 |
|
| 292 |
# Versioned static URLs. /static/ responses are cached for an hour, so without
|
| 293 |
# a version in the URL a deploy could serve new HTML with the old stylesheet and
|
|
|
|
| 288 |
from app import config # noqa: E402 (after `templates` exists, avoids a cycle)
|
| 289 |
|
| 290 |
templates.env.globals["space_app_url"] = config.SPACE_APP_URL
|
| 291 |
+
templates.env.globals["public_url"] = config.PUBLIC_URL
|
| 292 |
|
| 293 |
# Versioned static URLs. /static/ responses are cached for an hour, so without
|
| 294 |
# a version in the URL a deploy could serve new HTML with the old stylesheet and
|
|
@@ -208,6 +208,17 @@ TABLES: dict[str, dict] = {
|
|
| 208 |
"cols": ["user_id", "slug", "followed_at", "active", "updated_at"],
|
| 209 |
"blobs": [],
|
| 210 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
"search_log": {
|
| 212 |
"remote": "search_log",
|
| 213 |
"watermark": "id",
|
|
@@ -313,6 +324,9 @@ REMOTE_DDL = [
|
|
| 313 |
"""CREATE TABLE IF NOT EXISTS collection_follows (
|
| 314 |
user_id TEXT NOT NULL, slug TEXT NOT NULL, followed_at TEXT, active INTEGER,
|
| 315 |
updated_at TEXT, PRIMARY KEY (user_id, slug))""",
|
|
|
|
|
|
|
|
|
|
| 316 |
"""CREATE TABLE IF NOT EXISTS search_log (
|
| 317 |
id INTEGER PRIMARY KEY, created_at TEXT, query TEXT, query_id TEXT, n_results INTEGER,
|
| 318 |
mode TEXT, rewritten TEXT, latency_ms INTEGER, owner INTEGER, encode_ms INTEGER, rerank_ms INTEGER,
|
|
|
|
| 208 |
"cols": ["user_id", "slug", "followed_at", "active", "updated_at"],
|
| 209 |
"blobs": [],
|
| 210 |
},
|
| 211 |
+
# Library links (app/routers/library.py): a reader's link must keep working
|
| 212 |
+
# after a deploy, and a replaced link must stay dead. Uses are not pushed
|
| 213 |
+
# on their own (updated_at only changes on create and revoke).
|
| 214 |
+
"library_links": {
|
| 215 |
+
"remote": "library_links",
|
| 216 |
+
"watermark": "updated_at",
|
| 217 |
+
"wm_kind": "text",
|
| 218 |
+
"pk": ["token"],
|
| 219 |
+
"cols": ["token", "user_id", "created_at", "revoked", "updated_at", "uses"],
|
| 220 |
+
"blobs": [],
|
| 221 |
+
},
|
| 222 |
"search_log": {
|
| 223 |
"remote": "search_log",
|
| 224 |
"watermark": "id",
|
|
|
|
| 324 |
"""CREATE TABLE IF NOT EXISTS collection_follows (
|
| 325 |
user_id TEXT NOT NULL, slug TEXT NOT NULL, followed_at TEXT, active INTEGER,
|
| 326 |
updated_at TEXT, PRIMARY KEY (user_id, slug))""",
|
| 327 |
+
"""CREATE TABLE IF NOT EXISTS library_links (
|
| 328 |
+
token TEXT PRIMARY KEY, user_id TEXT NOT NULL, created_at TEXT, revoked INTEGER,
|
| 329 |
+
updated_at TEXT, uses INTEGER)""",
|
| 330 |
"""CREATE TABLE IF NOT EXISTS search_log (
|
| 331 |
id INTEGER PRIMARY KEY, created_at TEXT, query TEXT, query_id TEXT, n_results INTEGER,
|
| 332 |
mode TEXT, rewritten TEXT, latency_ms INTEGER, owner INTEGER, encode_ms INTEGER, rerank_ms INTEGER,
|
|
@@ -25,6 +25,10 @@ and deployed. Never copy old corpus counts or benchmark results into current cla
|
|
| 25 |
| Reader and search analytics | `search_log` (replicated): one row per search with the query (collapsed, at most 200 characters), its `query_id` (which result clicks and saves carry), result count, retrieval mode, the AI rewrite, time, and an owner flag; no reader is stored. `search_overviews` (replicated) keeps the AI overview per query and top five papers and is the overview cache (7 days). `reader_days` (replicated): one row per reader cookie per UTC day counting pages, searches, feed pages, papers opened, saves, passes and questions, owner = 1 for a browser holding the preview token, counted from every request by `analytics.observe()` in the HTTP middleware. Query text, rewrites, overviews and search subjects in `llm_calls` are cleared after 90 days locally and in Turso. Dashboards `/admin/readers`, `/admin/searches`, `/admin/ai/history` (owner only, own use left out unless `?me=1`) | `app/analytics.py`, `app/routers/admin.py` |
|
| 26 |
| Missing encodings | Available FTS query forms still run; actual contributing arms determine `retrieval_mode` | `app/hybrid_search_svc.py` |
|
| 27 |
| Search total miss | arXiv keyword fallback; no invented hits for unfamiliar concepts | `app/routers/search.py` |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
| Search results cache | In memory only (`app/search_cache.py`): a query's ranked results are reused for `SEARCH_CACHE_TTL_S` (600 s; 120 s when a retrieval arm was missing), keyed by the query with case and spacing ignored, at most 256 queries. Going back to a search, the paper page's back link, a reload or another reader's identical search costs no encode, Groq rewrite or retrieval. A reader coming back to the same results keeps their query_id and is not logged or counted again; that link is memory-only. `/healthz/runtime` counts `search_cache_hit` / `search_cache_miss`. Responses carry `Vary: HX-Request` and htmx fragments `Cache-Control: no-store`, so Back never shows a bare results fragment | `app/search_cache.py`, `app/routers/search.py`, `app/main.py` |
|
| 29 |
| Detailed interests | Saved papers -> long/short/negative EWMA. 2–4 saves: one interest per save; 5+: Ward medoids, K ≤ min(7, ceil(N/2)), finest singleton-free cut (2026-09-30) | `app/recommend/profiles.py`, `clustering.py` |
|
| 30 |
| Multi-interest balance | Importance-weighted quota, within-cluster MMR, quota-bound served order | `fusion.py`, `app/routers/recommendations.py` |
|
|
@@ -40,7 +44,7 @@ and deployed. Never copy old corpus counts or benchmark results into current cla
|
|
| 40 |
| Feedback semantics | Latest save/unsave/dismissal sets explicit state; click/view never overrides it; unsave survives cache reload | `get_current_feedback`, `get_save_history`, `user_state.py` |
|
| 41 |
| Library | All current saves; the 20-example retrieval deque no longer limits the library view. With `TRENDING_PAGE` visible, Library has its own tabs (Saved · Collections · Recent) and Trending takes Collections' place in the top and bottom bars; with it off the bars keep Collections (doc 06, 2026-10-25) | saved router, `partials/library_tabs.html`, `base.html` |
|
| 42 |
| Attribution | Ranked visits are clicks with origin fields; direct visits are views without fabricated policy/propensity. Card links carry their surface (`sf=search`, `recommendation`, `saved`) since the card-link fix (branch `fix/click-surface-baseline`); click rows before its deploy say `recommendation` whatever page they came from. Paper-page timings and explanation cache hits/misses appear in `/healthz/runtime`; `scripts/baseline_metrics.py` turns an interactions export into weekly reading metrics | `app/routers/paper.py`, `partials/paper_card.html`, `scripts/baseline_metrics.py` |
|
| 43 |
-
| Persistence | Local SQLite; periodic Turso replication of four core user tables plus the redesign's paper caches and logs (`paper_explanations`, `paper_abstracts`, `paper_sources`, `paper_briefings`, `paper_answers`, `llm_calls`, `content_reports`, `ai_daily`, `search_log`, `search_overviews`, `reader_days`), which use an AUTOINCREMENT `id` watermark and restore in pages of 2,000.
|
| 44 |
| Full abstracts | Behind `FULL_ABSTRACTS` (off by default). A paper whose stored abstract is cut at 500 characters is queued on first open; the arXiv API is called with up to 20 ids at least 3.1 s apart, honouring Retry-After, up to `FULL_ABSTRACTS_DAILY_CAP` ids a day. Saved abstracts replace stumps on the paper page and in `/explain`; queue state is in `/healthz/runtime` | `app/abstract_svc.py`, `app/routers/paper.py` |
|
| 45 |
| Paper sources | Behind `PAPER_SOURCES` (off, shadow, on). Opening a paper schedules one background fetch of `arxiv.org/html/<id>`; the page is parsed in a thread (standard-library parser) into licence, version, sections, paragraphs and figures. `paper_sources` (replicated, at most 24 figures) and local `paper_fulltext`/`paper_paragraphs` (pruned to `FULLTEXT_MAX_PAPERS`). A deploy or prune drops the local text while the row stays; `has_text()` tells, and `ensure(need_text=True)` (opening a paper, the briefing, Ask) fetches it again. Pacer: 1 request per 2 s, bursts of 3, for fetches a reader triggers; background work (the warm-up) also waits 15 s between its own requests, arXiv's robots.txt `Crawl-delay`. 3 soft blocks in 10 min open a 15-min breaker. Figures show for every licence unless `FIGURE_LICENCES` lists codes. `/healthz/sources` reports coverage | `app/paper_source_svc.py`, `app/arxiv_html.py`, `app/licences.py` |
|
| 46 |
| Figure thumbnails | Behind `FIGURES`. `/fig/<id>/<n>-<hash>.webp` serves a saved picture (PNG, JPEG, GIF) as a WebP at most 800 px wide, made with Pillow in a thread; JPEGs decode at reduced scale, so print-resolution exports work. `/fig/<id>/<n>-<hash>.svg` serves a vector figure, an SVG file or a drawing inline in the arXiv page (one page fetch per paper), rebuilt from drawing elements only by `app/svg_clean.py` and served with `Content-Security-Policy: default-src 'none'; …; sandbox`. Up to 24 figures per paper. Everything is fetched once from arXiv through the paper-source pacer and cached in `FIG_CACHE_DIR` (wiped on restart, swept to `FIG_CACHE_MAX_MB`). Rate limit 600 a minute per IP. A figure that can't be made is hidden by `app.js`. Every figure shows a credit and licence line | `app/routers/figures.py`, `app/thumbnails.py`, `app/svg_clean.py` |
|
|
|
|
| 25 |
| Reader and search analytics | `search_log` (replicated): one row per search with the query (collapsed, at most 200 characters), its `query_id` (which result clicks and saves carry), result count, retrieval mode, the AI rewrite, time, and an owner flag; no reader is stored. `search_overviews` (replicated) keeps the AI overview per query and top five papers and is the overview cache (7 days). `reader_days` (replicated): one row per reader cookie per UTC day counting pages, searches, feed pages, papers opened, saves, passes and questions, owner = 1 for a browser holding the preview token, counted from every request by `analytics.observe()` in the HTTP middleware. Query text, rewrites, overviews and search subjects in `llm_calls` are cleared after 90 days locally and in Turso. Dashboards `/admin/readers`, `/admin/searches`, `/admin/ai/history` (owner only, own use left out unless `?me=1`) | `app/analytics.py`, `app/routers/admin.py` |
|
| 26 |
| Missing encodings | Available FTS query forms still run; actual contributing arms determine `retrieval_mode` | `app/hybrid_search_svc.py` |
|
| 27 |
| Search total miss | arXiv keyword fallback; no invented hits for unfamiliar concepts | `app/routers/search.py` |
|
| 28 |
+
| Weak matches | A search whose best cross-encoded match scores below `SEARCH_WEAK_MATCH` (0.15) shows "None of these is a close match", keeps its results and skips the AI overview; not when a named paper was pinned. Counter `search_weak_match` (doc 06, 2026-11-17) | `app/routers/search.py`, `app/hybrid_search_svc.py` (`ce_top`) |
|
| 29 |
+
| Front page | `/` for a visitor without a finished onboarding and without any save, un-save or pass: search box and examples, "Personalise your feed", how the feed works, the week's 7 most upvoted Daily Papers as trending cards (Save, Pass; `policy_id = welcome_top_v1`, logged to `feed_exposures`). Replaces the redirect to `/onboarding`; onboarding has a link back (doc 06, 2026-11-17) | `app/routers/welcome.py`, `app/templates/welcome.html`, `app/main.py` |
|
| 30 |
+
| Library links | Library > Other devices (`/library/devices`): one private link per reader, `/l/<token>`, to open the same library in another browser; replace or turn off in one click. A browser with saves is asked first, then its saves and follows are added; switching requests must be same-site. `library_links` replicated. Rate limited | `app/routers/library.py`, `app/db.py` |
|
| 31 |
+
| Search engines and previews | `/robots.txt`, `/sitemap.xml` (≤ 5,000: public pages, collections, the week's papers, HN lasting, collection papers, papers with a plain summary; built at most every 6 h). `og:url` and canonical from `PUBLIC_URL` (https); `og:image` is the paper's first raster figure or `static/og.png` (`scripts/build_og_image.py`); `noindex` on search, Library, onboarding, admin. Paper pages have Share (share sheet or copy link) | `app/routers/seo.py`, `app/templates/base.html`, `app/routers/paper.py` |
|
| 32 |
| Search results cache | In memory only (`app/search_cache.py`): a query's ranked results are reused for `SEARCH_CACHE_TTL_S` (600 s; 120 s when a retrieval arm was missing), keyed by the query with case and spacing ignored, at most 256 queries. Going back to a search, the paper page's back link, a reload or another reader's identical search costs no encode, Groq rewrite or retrieval. A reader coming back to the same results keeps their query_id and is not logged or counted again; that link is memory-only. `/healthz/runtime` counts `search_cache_hit` / `search_cache_miss`. Responses carry `Vary: HX-Request` and htmx fragments `Cache-Control: no-store`, so Back never shows a bare results fragment | `app/search_cache.py`, `app/routers/search.py`, `app/main.py` |
|
| 33 |
| Detailed interests | Saved papers -> long/short/negative EWMA. 2–4 saves: one interest per save; 5+: Ward medoids, K ≤ min(7, ceil(N/2)), finest singleton-free cut (2026-09-30) | `app/recommend/profiles.py`, `clustering.py` |
|
| 34 |
| Multi-interest balance | Importance-weighted quota, within-cluster MMR, quota-bound served order | `fusion.py`, `app/routers/recommendations.py` |
|
|
|
|
| 44 |
| Feedback semantics | Latest save/unsave/dismissal sets explicit state; click/view never overrides it; unsave survives cache reload | `get_current_feedback`, `get_save_history`, `user_state.py` |
|
| 45 |
| Library | All current saves; the 20-example retrieval deque no longer limits the library view. With `TRENDING_PAGE` visible, Library has its own tabs (Saved · Collections · Recent) and Trending takes Collections' place in the top and bottom bars; with it off the bars keep Collections (doc 06, 2026-10-25) | saved router, `partials/library_tabs.html`, `base.html` |
|
| 46 |
| Attribution | Ranked visits are clicks with origin fields; direct visits are views without fabricated policy/propensity. Card links carry their surface (`sf=search`, `recommendation`, `saved`) since the card-link fix (branch `fix/click-surface-baseline`); click rows before its deploy say `recommendation` whatever page they came from. Paper-page timings and explanation cache hits/misses appear in `/healthz/runtime`; `scripts/baseline_metrics.py` turns an interactions export into weekly reading metrics | `app/routers/paper.py`, `partials/paper_card.html`, `scripts/baseline_metrics.py` |
|
| 47 |
+
| Persistence | Local SQLite; periodic Turso replication of four core user tables plus the redesign's paper caches and logs (`paper_explanations`, `paper_abstracts`, `paper_sources`, `paper_briefings`, `paper_answers`, `llm_calls`, `content_reports`, `ai_daily`, `search_log`, `search_overviews`, `reader_days`), which use an AUTOINCREMENT `id` watermark and restore in pages of 2,000. Since 2026-11-13 also feed impressions and exposures, collection follows and `ops_daily`; since 2026-11-17 `library_links`. Not replicated, so reset on every deploy: UI events, cluster snapshots, Ask's log and daily counter, paper full text and paragraphs (fetched again when needed), caches and thumbnails | `app/turso_sync.py:TABLES` |
|
| 48 |
| Full abstracts | Behind `FULL_ABSTRACTS` (off by default). A paper whose stored abstract is cut at 500 characters is queued on first open; the arXiv API is called with up to 20 ids at least 3.1 s apart, honouring Retry-After, up to `FULL_ABSTRACTS_DAILY_CAP` ids a day. Saved abstracts replace stumps on the paper page and in `/explain`; queue state is in `/healthz/runtime` | `app/abstract_svc.py`, `app/routers/paper.py` |
|
| 49 |
| Paper sources | Behind `PAPER_SOURCES` (off, shadow, on). Opening a paper schedules one background fetch of `arxiv.org/html/<id>`; the page is parsed in a thread (standard-library parser) into licence, version, sections, paragraphs and figures. `paper_sources` (replicated, at most 24 figures) and local `paper_fulltext`/`paper_paragraphs` (pruned to `FULLTEXT_MAX_PAPERS`). A deploy or prune drops the local text while the row stays; `has_text()` tells, and `ensure(need_text=True)` (opening a paper, the briefing, Ask) fetches it again. Pacer: 1 request per 2 s, bursts of 3, for fetches a reader triggers; background work (the warm-up) also waits 15 s between its own requests, arXiv's robots.txt `Crawl-delay`. 3 soft blocks in 10 min open a 15-min breaker. Figures show for every licence unless `FIGURE_LICENCES` lists codes. `/healthz/sources` reports coverage | `app/paper_source_svc.py`, `app/arxiv_html.py`, `app/licences.py` |
|
| 50 |
| Figure thumbnails | Behind `FIGURES`. `/fig/<id>/<n>-<hash>.webp` serves a saved picture (PNG, JPEG, GIF) as a WebP at most 800 px wide, made with Pillow in a thread; JPEGs decode at reduced scale, so print-resolution exports work. `/fig/<id>/<n>-<hash>.svg` serves a vector figure, an SVG file or a drawing inline in the arXiv page (one page fetch per paper), rebuilt from drawing elements only by `app/svg_clean.py` and served with `Content-Security-Policy: default-src 'none'; …; sandbox`. Up to 24 figures per paper. Everything is fetched once from arXiv through the paper-source pacer and cached in `FIG_CACHE_DIR` (wiped on restart, swept to `FIG_CACHE_MAX_MB`). Rate limit 600 a minute per IP. A figure that can't be made is hidden by `app.js`. Every figure shows a credit and licence line | `app/routers/figures.py`, `app/thumbnails.py`, `app/svg_clean.py` |
|
|
@@ -1534,3 +1534,58 @@ saves"; the 2026-09-30 entry's gap cut (its no-singleton rule stays).
|
|
| 1534 |
`enforce_quota_on_ranking`) kept: it orders the backfilled tail, so removing
|
| 1535 |
it is not output-neutral. Engagement-scaled quota waits for exposure data from
|
| 1536 |
real readers (replicated since this date).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1534 |
`enforce_quota_on_ranking`) kept: it orders the backfilled tail, so removing
|
| 1535 |
it is not output-neutral. Engagement-scaled quota waits for exposure data from
|
| 1536 |
real readers (replicated since this date).
|
| 1537 |
+
|
| 1538 |
+
### 2026-11-17 — The front door: a front page, library links, weak-match notice, search-engine basics
|
| 1539 |
+
**Decision:**
|
| 1540 |
+
* `/` shows a front page to any visitor without a finished onboarding and
|
| 1541 |
+
without a save, un-save or pass (`app/routers/welcome.py`): what ResearchIT
|
| 1542 |
+
is, a search box, example searches, "Personalise your feed" (the unchanged
|
| 1543 |
+
onboarding), "How the feed works", and the week's 7 most upvoted Daily
|
| 1544 |
+
Papers as trending cards with Save and Pass. It replaces the redirect to
|
| 1545 |
+
`/onboarding`. A save there marks onboarding done on the next visit, as
|
| 1546 |
+
any decision always did. The cards are a ranked surface: `query_id`,
|
| 1547 |
+
position, `propensity = 1.0` and `policy_id = welcome_top_v1` ride on each
|
| 1548 |
+
and go to `feed_exposures` (§3.11).
|
| 1549 |
+
* A reader's library opens in another browser from one private link,
|
| 1550 |
+
`/l/<token>` (128 random bits, not the user id): Library > Other devices
|
| 1551 |
+
makes, replaces or turns it off. A browser with no saves of its own
|
| 1552 |
+
switches at once; one with saves is asked, then its saves (where the
|
| 1553 |
+
library has no decision on the paper) and follows are added. Switching
|
| 1554 |
+
POSTs must come from this site (Sec-Fetch-Site / Origin). `library_links`
|
| 1555 |
+
replicates to Turso. Rate limits: `/l` 20 and `/api/library-link` 10 a
|
| 1556 |
+
minute per address.
|
| 1557 |
+
* A search whose best cross-encoded match is below `SEARCH_WEAK_MATCH = 0.15`
|
| 1558 |
+
says "None of these is a close match", keeps the results, and skips the AI
|
| 1559 |
+
overview. Not shown when a named paper was pinned.
|
| 1560 |
+
* `/robots.txt` (keeps crawlers off search, `/api/`, personal pages and
|
| 1561 |
+
library links) and `/sitemap.xml` (public pages, collections, this week's
|
| 1562 |
+
papers, Hacker News lasting papers, collection papers and papers with a
|
| 1563 |
+
plain-language summary; at most 5,000). Links that leave the site use
|
| 1564 |
+
`PUBLIC_URL` (https) for `og:url` and the canonical link; every page has a
|
| 1565 |
+
preview picture, the paper's first raster figure or `static/og.png`;
|
| 1566 |
+
personal pages and search results are `noindex`. Paper pages have Share.
|
| 1567 |
+
* Onboarding cards for High Energy Physics, Astrophysics, Condensed Matter,
|
| 1568 |
+
Physics (general) and Mathematics say how much of their pre-mid-2025
|
| 1569 |
+
literature the corpus holds (`AREA_COVERAGE_NOTES`).
|
| 1570 |
+
**Supersedes:** the Phase 5 rule "redirect new users to onboarding".
|
| 1571 |
+
**Rationale:**
|
| 1572 |
+
* Of the first 18 outside readers (24 Oct – 16 Nov), 8 never reached a feed,
|
| 1573 |
+
15 came only once. The form was the whole first impression; the feed,
|
| 1574 |
+
which 6 of them used heavily (25 saves), was behind it.
|
| 1575 |
+
* A reader is a cookie; a new device or cleared cookies lost everything, and
|
| 1576 |
+
there are no accounts or email to fall back on.
|
| 1577 |
+
* Weak-match threshold from the top cross-encoder probability over the dense
|
| 1578 |
+
top 10 (production text format, mxbai-xsmall, 256 tokens): below 0.15 are
|
| 1579 |
+
10 of 30 everyday web searches ("recipe for butter chicken", "Paytm product
|
| 1580 |
+
manager questions"), 1 of 100 known-answer research queries and none of 30
|
| 1581 |
+
short real queries ("lora", "mamba", "black massive holes"). Short
|
| 1582 |
+
everyday searches with real papers behind them ("bitcoin price today",
|
| 1583 |
+
0.76) are not flagged, and should not be.
|
| 1584 |
+
* Coverage notes from the sidecar: papers from 2024 against the 12 months
|
| 1585 |
+
from 2025-07 by primary category (hep 18%, cond-mat 32%, astro-ph 40%,
|
| 1586 |
+
physics.* 49%, the five maths categories 57% with algebraic geometry and
|
| 1587 |
+
PDE analysis near 25%); these fields grow a few percent a year, so the
|
| 1588 |
+
ratio is close to the share held.
|
| 1589 |
+
**Action items:** Done in code (branch `feat/front-door`). Next: email
|
| 1590 |
+
digest and sign-in by email link (needs a sending address), then invite
|
| 1591 |
+
readers and read `/admin/feed`.
|
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Draw app/static/og.png, the 1200x630 picture a shared ResearchIT link shows.
|
| 3 |
+
|
| 4 |
+
python scripts/build_og_image.py [--font /path/to/serif.ttc]
|
| 5 |
+
|
| 6 |
+
Paper pages with a saved figure use that figure instead (app/routers/paper.py).
|
| 7 |
+
The picture repeats the app's own look: graph paper, ink text, the green accent
|
| 8 |
+
and the book mark from the top bar. Run again after changing the wording.
|
| 9 |
+
Charter (Bitstream's free licence) ships with macOS; any serif works.
|
| 10 |
+
"""
|
| 11 |
+
from __future__ import annotations
|
| 12 |
+
|
| 13 |
+
import argparse
|
| 14 |
+
from pathlib import Path
|
| 15 |
+
|
| 16 |
+
from PIL import Image, ImageDraw, ImageFont
|
| 17 |
+
|
| 18 |
+
OUT = Path(__file__).resolve().parents[1] / "app" / "static" / "og.png"
|
| 19 |
+
W, H = 1200, 630
|
| 20 |
+
PAPER, INK, MUTED, ACCENT = (242, 238, 230), (22, 20, 15), (95, 88, 76), (44, 86, 56)
|
| 21 |
+
GRID, GRID_MAJOR = (229, 224, 213), (219, 212, 198)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def main() -> None:
|
| 25 |
+
ap = argparse.ArgumentParser()
|
| 26 |
+
ap.add_argument("--font", default="/System/Library/Fonts/Supplemental/Charter.ttc")
|
| 27 |
+
args = ap.parse_args()
|
| 28 |
+
img = Image.new("RGB", (W, H), PAPER)
|
| 29 |
+
d = ImageDraw.Draw(img)
|
| 30 |
+
for x in range(0, W, 24):
|
| 31 |
+
d.line([(x, 0), (x, H)], fill=GRID_MAJOR if x % 120 == 0 else GRID)
|
| 32 |
+
for y in range(0, H, 24):
|
| 33 |
+
d.line([(0, y), (W, y)], fill=GRID_MAJOR if y % 120 == 0 else GRID)
|
| 34 |
+
|
| 35 |
+
def font(size: int, index: int = 0):
|
| 36 |
+
return ImageFont.truetype(args.font, size, index=index)
|
| 37 |
+
|
| 38 |
+
# The book mark from base.html's top bar, scaled up.
|
| 39 |
+
s, ox, oy = 4.2, 96, 92
|
| 40 |
+
def p(x, y): return (ox + x * s, oy + y * s)
|
| 41 |
+
d.line([p(4, 20.5), p(4, 5.5), p(6.5, 3), p(19, 3), p(19, 18), p(6.5, 18), p(4, 20.5)], fill=ACCENT, width=8, joint="curve")
|
| 42 |
+
d.line([p(6.5, 18), p(19, 18), p(19, 21), p(6.5, 21), p(4, 20.5)], fill=ACCENT, width=8, joint="curve")
|
| 43 |
+
d.line([p(9, 8), p(15, 8)], fill=ACCENT, width=7)
|
| 44 |
+
d.line([p(9, 11.5), p(13, 11.5)], fill=ACCENT, width=7)
|
| 45 |
+
d.text((ox + 26 * s, oy + 14), "ResearchIT", font=font(60, 3), fill=INK)
|
| 46 |
+
|
| 47 |
+
d.text((96, 270), "Find the papers that matter", font=font(76, 3), fill=INK)
|
| 48 |
+
d.text((96, 360), "to your work.", font=font(76, 3), fill=INK)
|
| 49 |
+
d.text((96, 478), "Search 2 million arXiv papers in plain words, or get a feed", font=font(34), fill=MUTED)
|
| 50 |
+
d.text((96, 522), "that learns your separate interests from what you save.", font=font(34), fill=MUTED)
|
| 51 |
+
d.rectangle([0, H - 14, W, H], fill=ACCENT)
|
| 52 |
+
img.save(OUT, optimize=True)
|
| 53 |
+
print(f"wrote {OUT} ({OUT.stat().st_size // 1024} KB)")
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
if __name__ == "__main__":
|
| 57 |
+
main()
|
|
@@ -144,11 +144,13 @@ async def test_direct_paper_visit_keeps_history_but_not_skip_onboarding(client,
|
|
| 144 |
"""A shared link is often a reader's first visit; it must not count as history."""
|
| 145 |
from app.routers import paper
|
| 146 |
monkeypatch.setattr(paper, '_related', AsyncMock(return_value=[]))
|
| 147 |
-
|
|
|
|
|
|
|
| 148 |
assert (await client.get('/p/2305.04120')).status_code == 200
|
| 149 |
assert [r['paper_id'] for r in await db.get_recent_papers('reader')] == ['2305.04120']
|
| 150 |
home = await client.get('/')
|
| 151 |
-
assert home.status_code ==
|
| 152 |
assert (await db.get_onboarding_state('reader')) is None
|
| 153 |
|
| 154 |
|
|
|
|
| 144 |
"""A shared link is often a reader's first visit; it must not count as history."""
|
| 145 |
from app.routers import paper
|
| 146 |
monkeypatch.setattr(paper, '_related', AsyncMock(return_value=[]))
|
| 147 |
+
# A new visitor gets the front page (doc 06, 2026-11-17), not the feed.
|
| 148 |
+
first = await client.get('/')
|
| 149 |
+
assert first.status_code == 200 and 'class="wl-title"' in first.text
|
| 150 |
assert (await client.get('/p/2305.04120')).status_code == 200
|
| 151 |
assert [r['paper_id'] for r in await db.get_recent_papers('reader')] == ['2305.04120']
|
| 152 |
home = await client.get('/')
|
| 153 |
+
assert home.status_code == 200 and 'class="wl-title"' in home.text
|
| 154 |
assert (await db.get_onboarding_state('reader')) is None
|
| 155 |
|
| 156 |
|
|
@@ -39,7 +39,7 @@ def _wide_world() -> bool:
|
|
| 39 |
html = urllib.request.urlopen(req, timeout=15).read().decode()
|
| 40 |
except (urllib.error.URLError, OSError):
|
| 41 |
return False
|
| 42 |
-
# A new reader
|
| 43 |
return "data-wide-feed" in html or "/onboarding" in html
|
| 44 |
|
| 45 |
|
|
|
|
| 39 |
html = urllib.request.urlopen(req, timeout=15).read().decode()
|
| 40 |
except (urllib.error.URLError, OSError):
|
| 41 |
return False
|
| 42 |
+
# A new reader gets the front page (it links to /onboarding); a finished one sees the feed.
|
| 43 |
return "data-wide-feed" in html or "/onboarding" in html
|
| 44 |
|
| 45 |
|
|
@@ -212,8 +212,8 @@ def test_homepage_ships_an_h1_before_the_feed_loads(client):
|
|
| 212 |
visible title until the whole tier cascade had run (measured at 11s on a
|
| 213 |
cold production feed). A page's heading must not depend on a slow request.
|
| 214 |
"""
|
| 215 |
-
# A brand-new user
|
| 216 |
-
# otherwise this asserts against the
|
| 217 |
client.get("/")
|
| 218 |
client.post("/api/onboarding/skip")
|
| 219 |
|
|
|
|
| 212 |
visible title until the whole tier cascade had run (measured at 11s on a
|
| 213 |
cold production feed). A page's heading must not depend on a slow request.
|
| 214 |
"""
|
| 215 |
+
# A brand-new user gets the front page, so skip onboarding first —
|
| 216 |
+
# otherwise this asserts against the front page, not the feed page.
|
| 217 |
client.get("/")
|
| 218 |
client.post("/api/onboarding/skip")
|
| 219 |
|
|
@@ -0,0 +1,326 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
The front door (doc 06, 2026-11-17).
|
| 3 |
+
|
| 4 |
+
8 of the first 18 outside readers never reached a feed: / sent them straight
|
| 5 |
+
to a form. Now / shows a front page with search and the week's papers; a
|
| 6 |
+
library opens in another browser from a private link; a search with no close
|
| 7 |
+
match says so; search engines get robots.txt, a sitemap, https links and a
|
| 8 |
+
preview picture; onboarding marks the areas whose older papers are partial.
|
| 9 |
+
"""
|
| 10 |
+
import re
|
| 11 |
+
import xml.etree.ElementTree as ET
|
| 12 |
+
from unittest.mock import AsyncMock
|
| 13 |
+
|
| 14 |
+
import httpx
|
| 15 |
+
import pytest
|
| 16 |
+
|
| 17 |
+
from app import config, db, trending_shelf as ts, user_state as us
|
| 18 |
+
from app.main import app
|
| 19 |
+
|
| 20 |
+
WEEK = [f"2611.{i:05d}" for i in range(9)]
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def client(cookie: str | None = None, **headers):
|
| 24 |
+
c = httpx.AsyncClient(transport=httpx.ASGITransport(app=app), base_url="http://test", headers=headers)
|
| 25 |
+
if cookie: # the domain the app's Set-Cookie lands on, so a switch replaces it
|
| 26 |
+
c.cookies.set("arxiv_user_id", cookie, domain="test.local")
|
| 27 |
+
return c
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def week_paper(aid: str, votes: int) -> dict:
|
| 31 |
+
return {"arxiv_id": aid, "title": "Paper " + aid, "upvotes": votes,
|
| 32 |
+
"published_at": "2026-11-10T00:00:00+00:00", "listed_on": "2026-11-12", "categories": ["cs.LG"]}
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
@pytest.fixture(autouse=True)
|
| 36 |
+
def no_network(monkeypatch):
|
| 37 |
+
"""Library pages look papers up; these tests never reach Turso or arXiv."""
|
| 38 |
+
from app import arxiv_svc, turso_svc
|
| 39 |
+
|
| 40 |
+
async def meta(ids):
|
| 41 |
+
return {a: {"arxiv_id": a, "title": "Paper " + a, "abstract": "About it.", "authors": "[]",
|
| 42 |
+
"category": "cs.LG", "published": "2024-01-01"} for a in ids}
|
| 43 |
+
monkeypatch.setattr(turso_svc, "fetch_metadata_batch", meta)
|
| 44 |
+
monkeypatch.setattr(arxiv_svc, "fetch_metadata_batch", AsyncMock(return_value={}))
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
@pytest.fixture
|
| 48 |
+
def week(monkeypatch):
|
| 49 |
+
monkeypatch.setattr(ts, "_state", {**ts._state, "code": {}, "vectors": {},
|
| 50 |
+
"papers": {a: week_paper(a, 100 - i) for i, a in enumerate(WEEK)}})
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
async def save(user: str, pid: str, event: str = "save"):
|
| 54 |
+
await db.log_interaction(user_id=user, paper_id=pid, event_type=event, source="test")
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
# ── The front page ───────────────────────────────────────────────────────────
|
| 58 |
+
|
| 59 |
+
async def test_a_new_visitor_gets_the_front_page_not_a_form(week):
|
| 60 |
+
async with client() as c:
|
| 61 |
+
r = await c.get("/")
|
| 62 |
+
assert r.status_code == 200
|
| 63 |
+
page = r.text
|
| 64 |
+
assert 'class="wl-title"' in page and 'action="/search"' in page
|
| 65 |
+
assert 'href="/onboarding"' in page and "Personalise your feed" in page
|
| 66 |
+
assert "arxiv_user_id" in r.headers.get("set-cookie", "")
|
| 67 |
+
# The week's papers, most upvoted first, as real cards with Save buttons.
|
| 68 |
+
shown = re.findall(r'id="actions-([0-9.]+)"', page)
|
| 69 |
+
assert shown == WEEK[:7]
|
| 70 |
+
assert page.count('hx-post="/api/papers/') >= 7
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
async def test_front_page_cards_carry_their_ranking_fields_and_are_logged(week):
|
| 74 |
+
async with client("visitor-1") as c:
|
| 75 |
+
page = (await c.get("/")).text
|
| 76 |
+
href = re.search(r'href="(/p/2611\.00000\?[^"]+)"', page).group(1)
|
| 77 |
+
assert "sf=welcome" in href and "pol=welcome_top_v1" in href and "pos=0" in href and "prop=1.0" in href
|
| 78 |
+
import aiosqlite
|
| 79 |
+
async with aiosqlite.connect(config.DB_PATH) as conn:
|
| 80 |
+
rows = await (await conn.execute(
|
| 81 |
+
"SELECT paper_id, position, policy_id, propensity FROM feed_exposures WHERE user_id = 'visitor-1' "
|
| 82 |
+
"ORDER BY position")).fetchall()
|
| 83 |
+
assert [r[0] for r in rows] == WEEK[:7]
|
| 84 |
+
assert {r[2] for r in rows} == {"welcome_top_v1"} and {r[3] for r in rows} == {1.0}
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
async def test_front_page_without_this_weeks_papers_still_works(monkeypatch):
|
| 88 |
+
monkeypatch.setattr(ts, "_state", {**ts._state, "papers": {}})
|
| 89 |
+
async with client() as c:
|
| 90 |
+
r = await c.get("/")
|
| 91 |
+
assert r.status_code == 200 and 'class="wl-title"' in r.text and "Most upvoted this week" not in r.text
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
async def test_a_visitor_who_started_onboarding_is_invited_to_finish(week):
|
| 95 |
+
await db.save_onboarding_categories("half-done", ["nlp"])
|
| 96 |
+
async with client("half-done") as c:
|
| 97 |
+
page = (await c.get("/")).text
|
| 98 |
+
assert "Finish setting up your feed" in page
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
async def test_a_save_from_the_front_page_opens_the_feed_next_time(week):
|
| 102 |
+
async with client("saver") as c:
|
| 103 |
+
assert 'class="wl-title"' in (await c.get("/")).text
|
| 104 |
+
r = await c.post(f"/api/papers/{WEEK[0]}/save", data={"source": "welcome"})
|
| 105 |
+
assert r.status_code == 200
|
| 106 |
+
home = (await c.get("/")).text
|
| 107 |
+
assert 'class="wl-title"' not in home and 'id="rec-section"' in home
|
| 108 |
+
assert (await db.get_onboarding_state("saver"))["onboarding_completed"]
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
async def test_a_finished_onboarding_still_gets_the_feed(week):
|
| 112 |
+
await db.complete_onboarding("done")
|
| 113 |
+
async with client("done") as c:
|
| 114 |
+
home = (await c.get("/")).text
|
| 115 |
+
assert 'id="rec-section"' in home and 'class="wl-title"' not in home
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
async def test_onboarding_can_go_back_and_marks_partial_areas():
|
| 119 |
+
async with client("ob") as c:
|
| 120 |
+
page = (await c.get("/onboarding")).text
|
| 121 |
+
assert 'class="ob-back"' in page
|
| 122 |
+
for key, note in config.AREA_COVERAGE_NOTES.items():
|
| 123 |
+
card = re.search(rf'data-key="{key}".*?</button>', page, re.S).group(0)
|
| 124 |
+
assert note in card
|
| 125 |
+
nlp = re.search(r'data-key="nlp".*?</button>', page, re.S).group(0)
|
| 126 |
+
assert 'class="cov"' not in nlp
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
# ── Search engines and link previews ─────────────────────────────────────────
|
| 130 |
+
|
| 131 |
+
async def test_robots_txt_is_text_and_points_at_the_sitemap():
|
| 132 |
+
async with client() as c:
|
| 133 |
+
r = await c.get("/robots.txt")
|
| 134 |
+
assert r.status_code == 200 and r.headers["content-type"].startswith("text/plain")
|
| 135 |
+
assert "Disallow: /search" in r.text and "Disallow: /api/" in r.text and "Disallow: /l/" in r.text
|
| 136 |
+
assert f"Sitemap: {config.PUBLIC_URL}/sitemap.xml" in r.text
|
| 137 |
+
assert "<html" not in r.text
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
async def test_sitemap_lists_public_pages_and_papers_and_survives_a_failing_source(week, monkeypatch):
|
| 141 |
+
from app import collections_svc, hn_svc
|
| 142 |
+
from app.routers import seo
|
| 143 |
+
monkeypatch.setattr(seo, "_cache", {"at": 0.0, "body": ""})
|
| 144 |
+
monkeypatch.setattr(collections_svc, "load_all", lambda: [{"slug": "rag"}, {"slug": "agents"}])
|
| 145 |
+
monkeypatch.setattr(collections_svc, "anchor_ids", lambda slug: ["2005.11401"] if slug == "rag" else [])
|
| 146 |
+
|
| 147 |
+
def broken():
|
| 148 |
+
raise RuntimeError("hn not loaded")
|
| 149 |
+
monkeypatch.setattr(hn_svc, "lasting_cards", broken)
|
| 150 |
+
await db.save_explanation("k1", "1706.03762", "In plain terms.", "m")
|
| 151 |
+
async with client() as c:
|
| 152 |
+
r = await c.get("/sitemap.xml")
|
| 153 |
+
assert r.status_code == 200 and r.headers["content-type"].startswith("application/xml")
|
| 154 |
+
ns = {"s": "http://www.sitemaps.org/schemas/sitemap/0.9"}
|
| 155 |
+
locs = [e.text for e in ET.fromstring(r.text).findall("s:url/s:loc", ns)]
|
| 156 |
+
base = config.PUBLIC_URL
|
| 157 |
+
assert locs[0] == base + "/" and base + "/trending" in locs
|
| 158 |
+
assert base + "/collections/rag" in locs and base + "/collections/agents" in locs
|
| 159 |
+
assert base + f"/p/{WEEK[0]}" in locs and base + "/p/2005.11401" in locs and base + "/p/1706.03762" in locs
|
| 160 |
+
assert len(locs) == len(set(locs)) and all(u.startswith("https://") for u in locs)
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
async def test_sitemap_is_capped(week, monkeypatch):
|
| 164 |
+
from app.routers import seo
|
| 165 |
+
monkeypatch.setattr(seo, "SITEMAP_MAX", 6)
|
| 166 |
+
assert len(await seo.paths()) == 6
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
async def test_shared_links_say_https_and_carry_a_picture(week):
|
| 170 |
+
async with client() as c:
|
| 171 |
+
page = (await c.get("/")).text
|
| 172 |
+
assert f'<meta property="og:url" content="{config.PUBLIC_URL}/"' in page
|
| 173 |
+
assert f'<link rel="canonical" href="{config.PUBLIC_URL}/"' in page
|
| 174 |
+
assert f'<meta property="og:image" content="{config.PUBLIC_URL}/static/og.png"' in page
|
| 175 |
+
assert 'name="twitter:card" content="summary_large_image"' in page
|
| 176 |
+
assert config.PUBLIC_URL.startswith("https://")
|
| 177 |
+
import os
|
| 178 |
+
assert os.path.getsize("app/static/og.png") > 10_000
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
async def test_personal_and_search_pages_are_not_indexed(monkeypatch):
|
| 182 |
+
from app import hybrid_search_svc
|
| 183 |
+
# A result, so the search never falls back to arXiv's own API.
|
| 184 |
+
monkeypatch.setattr(hybrid_search_svc, "search", AsyncMock(return_value=(["2611.00001"], {})))
|
| 185 |
+
async with client("p") as c:
|
| 186 |
+
for path in ("/saved", "/history", "/library/devices", "/search?q=x"):
|
| 187 |
+
page = (await c.get(path)).text
|
| 188 |
+
assert '<meta name="robots" content="noindex"' in page, path
|
| 189 |
+
assert 'rel="canonical"' not in page, path
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
def test_a_paper_link_shows_its_first_raster_figure():
|
| 193 |
+
from app.routers.paper import share_image
|
| 194 |
+
assert share_image([]) is None
|
| 195 |
+
assert share_image([{"url": "/fig/1/0-a.svg"}]) is None
|
| 196 |
+
assert share_image([{"url": "/fig/1/0-a.svg"}, {"url": "/fig/1/1-b.webp"}]) == config.PUBLIC_URL + "/fig/1/1-b.webp"
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
# ── A search with no close match ─────────────────────────────────────────────
|
| 200 |
+
|
| 201 |
+
async def _search(monkeypatch, ce_top, named=None):
|
| 202 |
+
from app import hybrid_search_svc, turso_svc
|
| 203 |
+
meta = {"total_time_ms": 900, "retrieval_mode": "hybrid"}
|
| 204 |
+
if ce_top is not None:
|
| 205 |
+
meta["ce_top"] = ce_top
|
| 206 |
+
if named:
|
| 207 |
+
meta["named_paper"] = {"arxiv_id": named}
|
| 208 |
+
monkeypatch.setattr(hybrid_search_svc, "search", AsyncMock(return_value=(["2611.00001", "2611.00002"], meta)))
|
| 209 |
+
papers = {a: {"arxiv_id": a, "title": "T " + a, "abstract": "A.", "authors": "[]", "category": "cs.LG",
|
| 210 |
+
"published": "2026-11-01"} for a in ("2611.00001", "2611.00002")}
|
| 211 |
+
monkeypatch.setattr(turso_svc, "fetch_metadata_batch", AsyncMock(return_value=papers))
|
| 212 |
+
async with client("searcher", **{"HX-Request": "true"}) as c:
|
| 213 |
+
return (await c.get("/search?q=recipe+for+butter+chicken")).text
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
async def test_a_weak_search_says_so_and_skips_the_overview(monkeypatch):
|
| 217 |
+
html = await _search(monkeypatch, 0.04)
|
| 218 |
+
assert "None of these is a close match" in html
|
| 219 |
+
assert 'id="ai-summary-container"' not in html
|
| 220 |
+
assert "T 2611.00001" in html # the nearest papers are still shown
|
| 221 |
+
|
| 222 |
+
|
| 223 |
+
async def test_a_good_search_has_no_notice(monkeypatch):
|
| 224 |
+
html = await _search(monkeypatch, 0.62)
|
| 225 |
+
assert "close match" not in html and 'id="ai-summary-container"' in html
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
async def test_no_notice_without_a_score_or_when_a_paper_was_named(monkeypatch):
|
| 229 |
+
assert "close match" not in await _search(monkeypatch, None)
|
| 230 |
+
assert "close match" not in await _search(monkeypatch, 0.02, named="2611.00001")
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
async def test_the_notice_can_be_turned_off(monkeypatch):
|
| 234 |
+
monkeypatch.setattr(config, "SEARCH_WEAK_MATCH", 0.0)
|
| 235 |
+
assert "close match" not in await _search(monkeypatch, 0.02)
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
# ── Your library on another device ───────────────────────────────────────────
|
| 239 |
+
|
| 240 |
+
async def make_link(user: str) -> str:
|
| 241 |
+
async with client(user) as c:
|
| 242 |
+
r = await c.post("/api/library-link")
|
| 243 |
+
assert r.status_code == 303 and r.headers["location"].startswith("/library/devices")
|
| 244 |
+
page = (await c.get("/library/devices")).text
|
| 245 |
+
url = re.search(r'id="devlink-url" value="([^"]+)"', page).group(1)
|
| 246 |
+
assert url.startswith(config.PUBLIC_URL + "/l/")
|
| 247 |
+
return url.rsplit("/", 1)[1]
|
| 248 |
+
|
| 249 |
+
|
| 250 |
+
async def test_a_new_browser_opens_the_library_from_its_link():
|
| 251 |
+
await save("owner", "2401.00001")
|
| 252 |
+
token = await make_link("owner")
|
| 253 |
+
async with client() as phone:
|
| 254 |
+
r = await phone.get(f"/l/{token}")
|
| 255 |
+
assert r.status_code == 303 and r.headers["location"] == "/saved?opened=1"
|
| 256 |
+
assert phone.cookies.get("arxiv_user_id") == "owner"
|
| 257 |
+
page = (await phone.get("/saved?opened=1")).text
|
| 258 |
+
assert "Your library is open in this browser." in page
|
| 259 |
+
|
| 260 |
+
|
| 261 |
+
async def test_a_new_link_replaces_the_old_one_and_off_means_off():
|
| 262 |
+
old = await make_link("owner")
|
| 263 |
+
new = await make_link("owner")
|
| 264 |
+
assert old != new and len(new) >= 20
|
| 265 |
+
async with client() as c:
|
| 266 |
+
gone = await c.get(f"/l/{old}")
|
| 267 |
+
assert gone.status_code == 404 and "This link no longer works" in gone.text
|
| 268 |
+
assert (await c.get(f"/l/{new}")).status_code == 303
|
| 269 |
+
async with client("owner") as c:
|
| 270 |
+
await c.post("/api/library-link/revoke")
|
| 271 |
+
page = (await c.get("/library/devices")).text
|
| 272 |
+
assert "Make my library link" in page
|
| 273 |
+
async with client() as c:
|
| 274 |
+
assert (await c.get(f"/l/{new}")).status_code == 404
|
| 275 |
+
|
| 276 |
+
|
| 277 |
+
async def test_a_browser_with_its_own_saves_is_asked_then_merged():
|
| 278 |
+
await save("owner", "2401.00001")
|
| 279 |
+
await save("owner", "2401.00009", "not_interested")
|
| 280 |
+
await save("laptop", "2401.00002")
|
| 281 |
+
await save("laptop", "2401.00009") # the owner passed on this one: the owner's decision stays
|
| 282 |
+
await db.follow_collection("laptop", "rag")
|
| 283 |
+
token = await make_link("owner")
|
| 284 |
+
async with client("laptop") as c:
|
| 285 |
+
ask = await c.get(f"/l/{token}")
|
| 286 |
+
assert ask.status_code == 200 and "Open this library here?" in ask.text
|
| 287 |
+
assert c.cookies.get("arxiv_user_id") == "laptop" # nothing switched yet
|
| 288 |
+
r = await c.post(f"/l/{token}")
|
| 289 |
+
assert r.status_code == 303 and r.headers["location"] == "/saved?opened=1&added=1"
|
| 290 |
+
assert c.cookies.get("arxiv_user_id") == "owner"
|
| 291 |
+
feedback = {f["paper_id"]: f["event_type"] for f in await db.get_current_feedback("owner")}
|
| 292 |
+
assert feedback == {"2401.00001": "save", "2401.00002": "save", "2401.00009": "not_interested"}
|
| 293 |
+
assert "rag" in await db.get_followed_slugs("owner")
|
| 294 |
+
us._cache.clear()
|
| 295 |
+
assert "2401.00002" in (await us.ensure_loaded("owner")).positive_list
|
| 296 |
+
|
| 297 |
+
|
| 298 |
+
async def test_another_site_cannot_switch_a_library():
|
| 299 |
+
await save("victim", "2401.00003")
|
| 300 |
+
token = await make_link("attacker")
|
| 301 |
+
async with client("victim", **{"sec-fetch-site": "cross-site"}) as c:
|
| 302 |
+
assert (await c.post(f"/l/{token}")).status_code == 403
|
| 303 |
+
assert (await c.post("/api/library-link")).status_code == 403
|
| 304 |
+
async with client("victim", origin="https://evil.example") as c:
|
| 305 |
+
assert (await c.post(f"/l/{token}")).status_code == 403
|
| 306 |
+
assert await db.get_current_feedback("attacker") == []
|
| 307 |
+
assert await db.get_library_link("victim") is None
|
| 308 |
+
|
| 309 |
+
|
| 310 |
+
async def test_opening_your_own_link_changes_nothing():
|
| 311 |
+
token = await make_link("owner")
|
| 312 |
+
async with client("owner") as c:
|
| 313 |
+
r = await c.get(f"/l/{token}")
|
| 314 |
+
assert r.headers["location"] == "/saved?opened=here"
|
| 315 |
+
|
| 316 |
+
|
| 317 |
+
async def test_library_links_replicate_and_are_rate_limited():
|
| 318 |
+
import aiosqlite
|
| 319 |
+
from app import rate_limit, turso_sync
|
| 320 |
+
spec = turso_sync.TABLES["library_links"]
|
| 321 |
+
async with aiosqlite.connect(config.DB_PATH) as conn:
|
| 322 |
+
cols = {r[1] for r in await (await conn.execute("PRAGMA table_info(library_links)")).fetchall()}
|
| 323 |
+
assert set(spec["cols"]) <= cols and spec["watermark"] == "updated_at"
|
| 324 |
+
assert any("library_links" in ddl for ddl in turso_sync.REMOTE_DDL)
|
| 325 |
+
assert rate_limit._rule_for("/l/abc")[0] == "/l"
|
| 326 |
+
assert rate_limit._rule_for("/lasting") is None
|
|
@@ -34,16 +34,10 @@ def client(tmp_path, monkeypatch):
|
|
| 34 |
# ── Home page ─────────────────────────────────────────────────────────────────
|
| 35 |
|
| 36 |
def test_home_returns_200(client):
|
| 37 |
-
"""
|
| 38 |
resp = client.get("/", follow_redirects=False)
|
| 39 |
-
|
| 40 |
-
assert resp.
|
| 41 |
-
if resp.status_code == 302:
|
| 42 |
-
assert "/onboarding" in resp.headers.get("location", "")
|
| 43 |
-
# Follow the redirect
|
| 44 |
-
resp2 = client.get("/onboarding")
|
| 45 |
-
assert resp2.status_code == 200
|
| 46 |
-
assert "ResearchIT" in resp2.text
|
| 47 |
|
| 48 |
|
| 49 |
def test_home_sets_user_cookie(client):
|
|
|
|
| 34 |
# ── Home page ─────────────────────────────────────────────────────────────────
|
| 35 |
|
| 36 |
def test_home_returns_200(client):
|
| 37 |
+
"""A new visitor gets the front page itself, with a way into onboarding."""
|
| 38 |
resp = client.get("/", follow_redirects=False)
|
| 39 |
+
assert resp.status_code == 200
|
| 40 |
+
assert "ResearchIT" in resp.text and 'href="/onboarding"' in resp.text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
|
| 43 |
def test_home_sets_user_cookie(client):
|
|
@@ -322,3 +322,18 @@ def test_fragments_that_load_after_paint_are_marked_quiet(page):
|
|
| 322 |
html = get("/p/2609.31507").text
|
| 323 |
for marker in ('class="code-slot" data-quiet', 'id="panel-plain" role="tabpanel" aria-labelledby="tab-plain" data-quiet'):
|
| 324 |
assert marker in html
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 322 |
html = get("/p/2609.31507").text
|
| 323 |
for marker in ('class="code-slot" data-quiet', 'id="panel-plain" role="tabpanel" aria-labelledby="tab-plain" data-quiet'):
|
| 324 |
assert marker in html
|
| 325 |
+
|
| 326 |
+
|
| 327 |
+
def test_a_shared_paper_link_previews_with_its_figure_and_has_a_share_button(page, monkeypatch):
|
| 328 |
+
"""doc 06, 2026-11-17: links leave the site as https, with the key figure as their picture."""
|
| 329 |
+
monkeypatch.setenv("FIGURES", "on")
|
| 330 |
+
save_source(figures=2)
|
| 331 |
+
html = get("/p/2609.31507").text
|
| 332 |
+
assert f'<meta property="og:image" content="{config.PUBLIC_URL}/fig/2609.31507/0-' in html
|
| 333 |
+
assert f'<meta property="og:url" content="{config.PUBLIC_URL}/p/2609.31507"' in html
|
| 334 |
+
assert f'data-share="{config.PUBLIC_URL}/p/2609.31507"' in html
|
| 335 |
+
|
| 336 |
+
|
| 337 |
+
def test_a_paper_without_figures_previews_with_the_site_picture(page):
|
| 338 |
+
html = get("/p/2609.31507").text
|
| 339 |
+
assert f'<meta property="og:image" content="{config.PUBLIC_URL}/static/og.png"' in html
|