Skip to content

Commit

Permalink
bug fixes and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rleed committed Sep 24, 2023
1 parent 8c48a8a commit b6c0ee1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 8 additions & 1 deletion api/resolvers/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { proxyImages } from './imgproxy'
import { defaultCommentSort } from '../../lib/item'
import { createHmac } from './wallet'
import { settleHodlInvoice } from 'ln-service'
import { extractArticlePublishedDate } from '../../lib/timedate-scraper'

export async function commentFilterClause (me, models) {
let clause = ` AND ("Item"."weightedVotes" - "Item"."weightedDownVotes" > -${ITEM_FILTER_THRESHOLD}`
Expand Down Expand Up @@ -497,7 +498,13 @@ export default {
const html = await response.text()
const doc = domino.createWindow(html).document
const metadata = getMetadata(doc, url, { title: metadataRuleSets.title })
res.title = metadata?.title
const datedata = extractArticlePublishedDate({ url, doc })
console.log(datedata, (new Date() - datedata.date) / (1000 * 60 * 60 * 24))
const dateHint = (datedata && (new Date() - datedata.date) / (1000 * 60 * 60 * 24) > 365)
? ` (${datedata.date.getFullYear()})`
: ''

res.title = metadata?.title + dateHint
} catch { }

try {
Expand Down
5 changes: 3 additions & 2 deletions lib/timedate-scraper.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
const { getMetadata } = require('page-metadata-parser')
const domino = require('domino')
const { ensureProtocol } = require('./url')

// Get a publication date given a URL.
//
// Ported from https://github.com/Webhose/article-date-extractor/blob/master/articleDateExtractor/__init__.py
//
// Example usage:
//
// import { loadURL, extractArticlePublishedDate } from './lib.js'
// import { loadURL, extractArticlePublishedDate } from './lib/timedate-scraper.js'
// console.log(extractArticlePublishedDate(await loadURL('https://finance.yahoo.com/news/europe-spot-bitcoin-etf-means-090100353.html')))

exports.loadURL = async function (url) {
const response = await fetch(url)
const response = await fetch(ensureProtocol(url), { redirect: 'follow' })
const html = await response.text()
return { url, doc: domino.createWindow(html).document }
}
Expand Down

0 comments on commit b6c0ee1

Please sign in to comment.