From a8006177c3214a65b879784a725271a4e27e1c1c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christoffer=20A=CC=8Ahrling?=
Date: Fri, 28 Feb 2020 14:04:34 +0100
Subject: [PATCH 01/27] Load and display similar stories
---
package.json | 1 +
src/api/create-api-client.js | 4 ++++
src/api/create-api-server.js | 5 +++++
src/api/index.js | 15 +++++++++++++-
src/components/Item.vue | 4 ++++
src/components/Similar.vue | 39 ++++++++++++++++++++++++++++++++++++
src/store/actions.js | 16 +++++++++++++--
src/views/ItemView.vue | 4 +++-
8 files changed, 84 insertions(+), 4 deletions(-)
create mode 100644 src/components/Similar.vue
diff --git a/package.json b/package.json
index b8c7a74c8..be36d771e 100644
--- a/package.json
+++ b/package.json
@@ -23,6 +23,7 @@
"extract-text-webpack-plugin": "^3.0.2",
"firebase": "4.6.2",
"lru-cache": "^4.1.1",
+ "node-fetch": "^2.6.0",
"route-cache": "0.4.3",
"serve-favicon": "^2.4.5",
"vue": "^2.5.22",
diff --git a/src/api/create-api-client.js b/src/api/create-api-client.js
index 1a92e7415..e823dc9a3 100644
--- a/src/api/create-api-client.js
+++ b/src/api/create-api-client.js
@@ -5,3 +5,7 @@ export function createAPI ({ config, version }) {
Firebase.initializeApp(config)
return Firebase.database().ref(version)
}
+
+export function fetchData(...params) {
+ return window.fetch(...params);
+}
diff --git a/src/api/create-api-server.js b/src/api/create-api-server.js
index f7bb7d1fc..18745226a 100644
--- a/src/api/create-api-server.js
+++ b/src/api/create-api-server.js
@@ -1,5 +1,6 @@
import Firebase from 'firebase'
import LRU from 'lru-cache'
+import fetch from 'node-fetch';
export function createAPI ({ config, version }) {
let api
@@ -29,3 +30,7 @@ export function createAPI ({ config, version }) {
}
return api
}
+
+export function fetchData(...params) {
+ return fetch(...params);
+}
diff --git a/src/api/index.js b/src/api/index.js
index 46ccc77fc..a650f01a4 100644
--- a/src/api/index.js
+++ b/src/api/index.js
@@ -1,5 +1,5 @@
// this is aliased in webpack config based on server/client build
-import { createAPI } from 'create-api'
+import { createAPI, fetchData } from 'create-api'
const logRequests = !!process.env.DEBUG_API
@@ -74,3 +74,16 @@ export function watchList (type, cb) {
ref.off('value', handler)
}
}
+
+export function fetchSimilarStories(story) {
+ return fetchData('https://textsimilarity.research.peltarion.com/query', {
+ method: 'POST',
+ body: JSON.stringify({
+ query: story.title,
+ dataset: 'hn-sbert',
+ top_n: 5
+ })
+ })
+ .then(resp => resp.json())
+ .then(json => json.entries);
+}
diff --git a/src/components/Item.vue b/src/components/Item.vue
index 156a68390..bca4d1ce8 100644
--- a/src/components/Item.vue
+++ b/src/components/Item.vue
@@ -22,15 +22,19 @@
| {{ item.descendants }} comments
+
+
{{ item.type }}
+
+
diff --git a/src/store/actions.js b/src/store/actions.js
index 258dcfbda..08c2d6107 100644
--- a/src/store/actions.js
+++ b/src/store/actions.js
@@ -1,7 +1,8 @@
import {
fetchUser,
fetchItems,
- fetchIdsByType
+ fetchIdsByType,
+ fetchSimilarStories
} from '../api'
export default {
@@ -35,7 +36,18 @@ export default {
return false
})
if (ids.length) {
- return fetchItems(ids).then(items => commit('SET_ITEMS', { items }))
+ return fetchItems(ids)
+ .then(items => {
+ if (items.every(item => item.type === 'story')) {
+ return Promise.all(items.map(i => fetchSimilarStories(i)))
+ .then(similar => items.map((item, idx) => {
+ item.similar = similar[idx];
+ return item;
+ }))
+ }
+ return items;
+ })
+ .then(items => commit('SET_ITEMS', { items }))
} else {
return Promise.resolve()
}
diff --git a/src/views/ItemView.vue b/src/views/ItemView.vue
index bc6a09794..69e8837b2 100644
--- a/src/views/ItemView.vue
+++ b/src/views/ItemView.vue
@@ -13,6 +13,7 @@
| by {{ item.by }}
{{ item.time | timeAgo }} ago
+
@@ -30,10 +31,11 @@ From 22060e72d7ca95e2fe0dc32dafff9688931c8bb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoffer=20A=CC=8Ahrling?=
Date: Fri, 20 Mar 2020 16:38:09 +0100
Subject: [PATCH 06/27] fetch similar posts and not only the score
---
src/components/Similar.vue | 4 ++--
src/store/actions.js | 14 ++++++++++++++
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/src/components/Similar.vue b/src/components/Similar.vue
index 37072dff5..2e82f8537 100644
--- a/src/components/Similar.vue
+++ b/src/components/Similar.vue
@@ -4,8 +4,8 @@
Similar:
-
-
-
{{ sim.text }}
+
+ {{ sim.title }} | {{ new Date(sim.time * 1000).getFullYear() }} | {{ sim.descendants }} comments
diff --git a/src/store/actions.js b/src/store/actions.js
index 1f3e055fa..fc1ef2691 100644
--- a/src/store/actions.js
+++ b/src/store/actions.js
@@ -45,6 +45,20 @@ export default {
item.similar = similar[idx];
return item;
}))
+ // Start fetching similar posts (potential performance issue...)
+ .then((items) => {
+ return fetchItems(items.map(i => i.similar).flat().map(sim => sim.id))
+ .then(similarItems => {
+ items.forEach(item => {
+ item.similar = item.similar.map(sim => {
+ const simItem = similarItems.find(si => si.id === sim.id);
+ return Object.assign({ similarity_score: sim.score }, simItem);
+ });
+ });
+ return items;
+ });
+ });
+ // Stop fetching similar posts (potential performance issue...)
}
return items;
})
From 0333fd67bcee310508ff3de8ac824070d8e198b9 Mon Sep 17 00:00:00 2001
From: philipp-eisen <8607233+philipp-eisen@users.noreply.github.com>
Date: Fri, 20 Mar 2020 17:05:35 +0100
Subject: [PATCH 07/27] Add Dockerfile
---
Dockerfile | 7 +++++++
package.json | 4 ++--
2 files changed, 9 insertions(+), 2 deletions(-)
create mode 100644 Dockerfile
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 000000000..ebc14d509
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,7 @@
+FROM node:13.10.1-buster
+
+COPY . /app/src
+WORKDIR /app/src
+RUN npm i && \
+ npm run build
+CMD ["npm", "run", "start"]
\ No newline at end of file
diff --git a/package.json b/package.json
index be36d771e..8a298435a 100644
--- a/package.json
+++ b/package.json
@@ -1,5 +1,5 @@
{
- "name": "vue-hackernews-2.0",
+ "name": "nostalgia-hn",
"description": "A Vue.js project",
"author": "Evan You ",
"private": true,
@@ -55,4 +55,4 @@
"webpack-merge": "^4.2.1",
"webpack-node-externals": "^1.7.2"
}
-}
+}
\ No newline at end of file
From 28d0a9b8326ecfa08d9d55a7e241d3fc5b53ed25 Mon Sep 17 00:00:00 2001
From: Philipp Eisen
Date: Sun, 29 Mar 2020 18:28:34 +0200
Subject: [PATCH 08/27] Change page titles to Nostalgia HN
---
manifest.json | 56 +++++++++++++++++++++++------------------------
server.js | 8 +++----
src/util/title.js | 10 ++++-----
3 files changed, 37 insertions(+), 37 deletions(-)
diff --git a/manifest.json b/manifest.json
index 5e30b54cb..aed32646b 100644
--- a/manifest.json
+++ b/manifest.json
@@ -1,37 +1,37 @@
{
- "name": "Vue Hackernews 2.0",
- "short_name": "Vue HN",
+ "name": "Nostalgia HN",
+ "short_name": "N7a HN",
"icons": [{
- "src": "/public/logo-120.png",
- "sizes": "120x120",
- "type": "image/png"
- }, {
- "src": "/public/logo-144.png",
- "sizes": "144x144",
- "type": "image/png"
- }, {
- "src": "/public/logo-152.png",
- "sizes": "152x152",
- "type": "image/png"
- }, {
- "src": "/public/logo-192.png",
- "sizes": "192x192",
- "type": "image/png"
- }, {
- "src": "/public/logo-256.png",
- "sizes": "256x256",
- "type": "image/png"
- }, {
- "src": "/public/logo-384.png",
- "sizes": "384x384",
- "type": "image/png"
- }, {
+ "src": "/public/logo-120.png",
+ "sizes": "120x120",
+ "type": "image/png"
+ }, {
+ "src": "/public/logo-144.png",
+ "sizes": "144x144",
+ "type": "image/png"
+ }, {
+ "src": "/public/logo-152.png",
+ "sizes": "152x152",
+ "type": "image/png"
+ }, {
+ "src": "/public/logo-192.png",
+ "sizes": "192x192",
+ "type": "image/png"
+ }, {
+ "src": "/public/logo-256.png",
+ "sizes": "256x256",
+ "type": "image/png"
+ }, {
+ "src": "/public/logo-384.png",
+ "sizes": "384x384",
+ "type": "image/png"
+ }, {
"src": "/public/logo-512.png",
"sizes": "512x512",
"type": "image/png"
- }],
+ }],
"start_url": "/",
"background_color": "#f2f3f5",
"display": "standalone",
"theme_color": "#f60"
-}
+}
\ No newline at end of file
diff --git a/server.js b/server.js
index f7b7330b5..de2301188 100644
--- a/server.js
+++ b/server.js
@@ -16,7 +16,7 @@ const serverInfo =
const app = express()
-function createRenderer (bundle, options) {
+function createRenderer(bundle, options) {
// https://github.com/vuejs/vue/blob/dev/packages/vue-server-renderer/README.md#why-use-bundlerenderer
return createBundleRenderer(bundle, Object.assign(options, {
// for component caching
@@ -78,7 +78,7 @@ app.use('/service-worker.js', serve('./dist/service-worker.js'))
// https://www.nginx.com/blog/benefits-of-microcaching-nginx/
app.use(microcache.cacheSeconds(1, req => useMicroCache && req.originalUrl))
-function render (req, res) {
+function render(req, res) {
const s = Date.now()
res.setHeader("Content-Type", "text/html")
@@ -87,7 +87,7 @@ function render (req, res) {
const handleError = err => {
if (err.url) {
res.redirect(err.url)
- } else if(err.code === 404) {
+ } else if (err.code === 404) {
res.status(404).send('404 | Page Not Found')
} else {
// Render Error Page or Redirect
@@ -98,7 +98,7 @@ function render (req, res) {
}
const context = {
- title: 'Vue HN 2.0', // default title
+ title: 'Nostalgia HN', // default title
url: req.url
}
renderer.renderToString(context, (err, html) => {
diff --git a/src/util/title.js b/src/util/title.js
index 664e0594c..172636527 100644
--- a/src/util/title.js
+++ b/src/util/title.js
@@ -1,4 +1,4 @@
-function getTitle (vm) {
+function getTitle(vm) {
const { title } = vm.$options
if (title) {
return typeof title === 'function'
@@ -8,19 +8,19 @@ function getTitle (vm) {
}
const serverTitleMixin = {
- created () {
+ created() {
const title = getTitle(this)
if (title) {
- this.$ssrContext.title = `Vue HN 2.0 | ${title}`
+ this.$ssrContext.title = `Nostalgia HN | ${title}`
}
}
}
const clientTitleMixin = {
- mounted () {
+ mounted() {
const title = getTitle(this)
if (title) {
- document.title = `Vue HN 2.0 | ${title}`
+ document.title = `Nostalgia HN | ${title}`
}
}
}
From 111e6facee2602fb6592140a8d1dd0e0d07f3c8c Mon Sep 17 00:00:00 2001
From: Philipp Eisen
Date: Sat, 25 Apr 2020 13:31:21 +0200
Subject: [PATCH 09/27] Add footer with credits
---
src/App.vue | 220 +++++++++++++++++++++++++---------------
src/index.template.html | 53 ++++++----
src/views/ItemList.vue | 211 ++++++++++++++++++++------------------
src/views/ItemView.vue | 157 ++++++++++++++++------------
4 files changed, 378 insertions(+), 263 deletions(-)
diff --git a/src/App.vue b/src/App.vue
index ff8643cab..3298f726c 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -3,100 +3,158 @@
+
+
diff --git a/src/index.template.html b/src/index.template.html
index 56fdcec30..98287a7f4 100644
--- a/src/index.template.html
+++ b/src/index.template.html
@@ -1,23 +1,38 @@
-
- {{ title }}
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+ {{ title }}
+
+
+
+
+
+
+
+
+
+
+
+
+
skip to content
-
-
+
+
+