diff --git a/config.py b/config.py index e534569..78724ab 100644 --- a/config.py +++ b/config.py @@ -1,3 +1,4 @@ user_agent = "HNClient (in development)" debug = True # redis_socket = "/run/redis-hnreader/redis-server.sock" +redis_socket = False diff --git a/hnapi/__init__.py b/hnapi/__init__.py index 43e1359..ce8cf6d 100644 --- a/hnapi/__init__.py +++ b/hnapi/__init__.py @@ -39,8 +39,9 @@ class HNClient: item["kids"] = kids return item - async def get_stories(self, page: str, limit=25, offset=0): - key = f"hnclient_stories_{page}_{limit}" + async def get_stories(self, page: str, offset=0): + limit = 25 + key = f"hnclient_stories_{page}_{offset}" cached = self.r.get(key) if cached: return json.loads(cached) @@ -48,7 +49,7 @@ class HNClient: async with self.s.get(url) as response: response.raise_for_status() stories = await response.json() - stories = stories[offset:limit] + stories = stories[offset:limit + offset] tasks = [] for id in stories: task = asyncio.ensure_future(self.get_item(id)) diff --git a/server.py b/server.py index 343e0cb..0766b37 100644 --- a/server.py +++ b/server.py @@ -47,7 +47,8 @@ async def read(request: Request): async def topstories(request: Request): - data = await api.get_stories("topstories") + offset = int(request.query_params.get("offset", 0)) + data = await api.get_stories("topstories", offset=offset) return JSONResponse(data) diff --git a/web/public/index.html b/web/public/index.html index 1f1aad6..983b4e2 100644 --- a/web/public/index.html +++ b/web/public/index.html @@ -2,9 +2,10 @@ - + + + - Snowpack App diff --git a/web/public/robots.txt b/web/public/robots.txt new file mode 100644 index 0000000..1f53798 --- /dev/null +++ b/web/public/robots.txt @@ -0,0 +1,2 @@ +User-agent: * +Disallow: / diff --git a/web/publish.sh b/web/publish.sh new file mode 100755 index 0000000..aaf7393 --- /dev/null +++ b/web/publish.sh @@ -0,0 +1,2 @@ +#!/bin/bash +rsync -aP build/* lw1.at:/srv/server/hnreader/static diff --git a/web/src/router.ts b/web/src/router.ts index e0ab8b3..30e4466 100644 --- a/web/src/router.ts +++ b/web/src/router.ts @@ -1,11 +1,19 @@ -import {createRouter, createWebHistory} from "vue-router"; -import Stories from './views/Stories.vue'; +import {createRouter, createWebHashHistory, createWebHistory} from "vue-router"; import About from './views/About.vue'; import Comments from "./views/Comments.vue"; import Reader from "./views/Reader.vue"; +import {isInStandaloneMode} from "./utils"; + +let history; + +if (isInStandaloneMode()) { + history = createWebHashHistory() +} else { + history = createWebHistory() +} export const router = createRouter({ - history: createWebHistory(), + history: history, routes: [ {path: '/', name: "about", component: About}, {path: "/comments/:item", name: "comments", component: Comments, props: true}, diff --git a/web/src/style/_layout.scss b/web/src/style/_layout.scss index e0034fc..13124ca 100644 --- a/web/src/style/_layout.scss +++ b/web/src/style/_layout.scss @@ -7,6 +7,7 @@ html, body { left: 0; right: 0; bottom: 0; + background: $color; } @@ -14,6 +15,7 @@ html, body { height: 100%; display: flex; width: 100%; + background: white; } #sidebar .stories, #mainpane .comments, #mainpane .reader { diff --git a/web/src/style/main.scss b/web/src/style/main.scss index ec53143..46cc393 100644 --- a/web/src/style/main.scss +++ b/web/src/style/main.scss @@ -84,6 +84,9 @@ pre { background: lightgray; } } + .load-more { + height: 50px; + } } .comments { diff --git a/web/src/utils.ts b/web/src/utils.ts index 4c67681..23a5f4b 100644 --- a/web/src/utils.ts +++ b/web/src/utils.ts @@ -31,3 +31,6 @@ export function dateToText(timestamp: number): string { const date = new Date(timestamp * 1000) return date.toLocaleString() } + +// @ts-ignore +export const isInStandaloneMode = () => ('standalone' in window.navigator) && (window.navigator.standalone); diff --git a/web/src/views/Reader.vue b/web/src/views/Reader.vue index 3a33630..0934a02 100644 --- a/web/src/views/Reader.vue +++ b/web/src/views/Reader.vue @@ -5,7 +5,7 @@
{{ prettyDate }}
{{ prettyAuthors }}
-
{{ readerData }}
+ diff --git a/web/src/views/Stories.vue b/web/src/views/Stories.vue index 3eeced6..46e0b08 100644 --- a/web/src/views/Stories.vue +++ b/web/src/views/Stories.vue @@ -12,7 +12,8 @@
{{ story.score }}
-
{{ stories }}
+
LOAD MORE
+ @@ -20,23 +21,28 @@ import {defineComponent} from "vue"; import {Item} from "../interfaces"; import {dateToText} from "../utils"; + +const STORIES_PER_LOAD = 25; + export default defineComponent({ name: "Stories", data() { return { - stories: [] as Item[] + stories: [] as Item[], } }, methods: { loadStory(): void { - fetch("/api/topstories") + fetch("/api/topstories?" + new URLSearchParams({ + offset: this.stories.length.toString() + })) .then(response => { if (response.ok) { return response.json() } return Promise.reject(response) }) - .then(data => (this.stories = data)) + .then(data => (this.stories.push(...data))) }, isActiveStory(item: Item): boolean { return this.$route.params.item === item.id.toString()