mirror of
https://github.com/only-cli/oc.git
synced 2026-09-15 10:40:56 +02:00
Closes #3. An API answer is a page: jsonToHTML turns a JSON body into one article per item, and everything downstream (numbering, budget, do, read, next, raw) treats it as an ordinary document. No per-site logic and no new dependency. The compact view is the hard part, since a search response carries far more fields than fit in 500 tokens. So the renderer scores each field by how much it varies across items against how wide it prints, penalises fields flattened out of a sub-object (owner.reputation describes the asker, not the answer), and spends about 60 characters per item on the winners. What every item shares is stated once at the bottom instead of repeated, empty fields are named rather than printed, and what was cut says so and points at oc raw, which keeps every field. On the Stack Exchange search endpoint that is 30 results in ~960 tokens against ~5,500 for the raw body, with each title a link and question_id visible. Also here: - clis/stackoverflow.com.json gains search <query>, which is what #3 was blocking. Results carry question_id, and the question feed reads one in full, so search now completes without touching the challenged HTML page. - fetch: the native-fetch path rejected anything that was not HTML or XML. It now accepts JSON, which also makes the two transports render one URL the same way, since the impers path never checked the type at all. - raw threads the URL through so its view of an API response can be titled and, unlike the compact view, keeps every field. Deliberately not done, from the notes on the issue: pagination in the actions line, and API metadata on stderr. There is no stderr channel at the distill seam, so response-level fields (has_more, quota_remaining) render as one footer line instead. A columns hint in the clis specs and a --json passthrough both looked like the wrong trade: the first needs per-site tuning for something the scoring already handles, the second would break the machine-stable Page contract.
72 lines
2.3 KiB
JSON
72 lines
2.3 KiB
JSON
{
|
|
"items": [
|
|
{
|
|
"tags": ["physics", "optics"],
|
|
"owner": {
|
|
"account_id": 1,
|
|
"reputation": 5120,
|
|
"user_id": 11,
|
|
"display_name": "Ray Leigh",
|
|
"profile_image": "https://example.test/img/1.png?s=256",
|
|
"link": "https://example.test/users/11/ray-leigh"
|
|
},
|
|
"is_answered": true,
|
|
"closed_date": null,
|
|
"view_count": 91234,
|
|
"answer_count": 4,
|
|
"score": 512,
|
|
"creation_date": 1340805096,
|
|
"question_id": 42,
|
|
"content_license": "CC BY-SA 4.0",
|
|
"link": "https://example.test/questions/42/why-is-the-sky-blue",
|
|
"title": "Why is the sky blue, and why does "blue" scatter most?",
|
|
"body": "<p>Looking up on a clear day the sky is blue, yet sunlight is white.</p>\n<pre><code>wavelength < 450nm\n</code></pre>\n<p>What scatters the shorter wavelengths? See <a href=\"https://example.test/scattering\">the derivation</a>.</p>"
|
|
},
|
|
{
|
|
"tags": ["optics"],
|
|
"owner": {
|
|
"account_id": 2,
|
|
"reputation": 87,
|
|
"user_id": 12,
|
|
"display_name": "Tyndall",
|
|
"profile_image": "https://example.test/img/2.png?s=256",
|
|
"link": "https://example.test/users/12/tyndall"
|
|
},
|
|
"is_answered": true,
|
|
"closed_date": null,
|
|
"view_count": 300,
|
|
"answer_count": 1,
|
|
"score": 7,
|
|
"creation_date": 1340808000,
|
|
"question_id": 43,
|
|
"content_license": "CC BY-SA 4.0",
|
|
"link": "https://example.test/questions/43/what-is-tyndall-scattering",
|
|
"title": "What is Tyndall scattering?"
|
|
},
|
|
{
|
|
"tags": ["physics", "atmosphere"],
|
|
"owner": {
|
|
"account_id": 3,
|
|
"reputation": 1904,
|
|
"user_id": 13,
|
|
"display_name": "Mie",
|
|
"profile_image": "https://example.test/img/3.png?s=256",
|
|
"link": "https://example.test/users/13/mie"
|
|
},
|
|
"is_answered": true,
|
|
"closed_date": null,
|
|
"view_count": 1580,
|
|
"answer_count": 2,
|
|
"score": 33,
|
|
"creation_date": 1340900000,
|
|
"question_id": 44,
|
|
"content_license": "CC BY-SA 4.0",
|
|
"link": "https://example.test/questions/44/why-are-sunsets-red",
|
|
"title": "Why are sunsets red?"
|
|
}
|
|
],
|
|
"has_more": true,
|
|
"quota_max": 300,
|
|
"quota_remaining": 297
|
|
}
|