-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
1,066 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
build | ||
node_modules | ||
.envrc | ||
.envrc | ||
googleServiceAccount.json | ||
stats.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
book: | ||
isbn: 9780566076275 | ||
tags: | ||
- management |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const Git = require("nodegit") | ||
|
||
class GitFile { | ||
constructor(location) { | ||
this.location = location | ||
} | ||
revs(count, order = Git.Revwalk.SORT.REVERSE) { | ||
return Git.Repository | ||
.open(".") | ||
.then(repo => repo.getMasterCommit().then(master => ([repo, master]))) | ||
.then(([repo, master]) => { | ||
let walker = repo.createRevWalk() | ||
walker.push(master.sha()) | ||
walker.sorting(order) | ||
return walker.fileHistoryWalk(this.location, count)}) | ||
} | ||
} | ||
|
||
module.exports = GitFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Feed } from "feed" | ||
import GitFile from './classes/GitFile' | ||
|
||
const max = (among, attr) => new Date(Math.max(...among.map(item => attr(item)))) | ||
|
||
const emptyFeed = new Feed({ | ||
title: 'The best books for developers – mustread.tech', | ||
description: "Open-source and crowd-sourced book listing", | ||
link: "http://mustread.tech", | ||
id: "http://static.mustread.tech/rss.xml", | ||
author: { | ||
name: "Eduards Sizovs" | ||
}, | ||
}) | ||
|
||
module.exports = books => | ||
Promise | ||
.all(books | ||
.map(book => | ||
new GitFile(book.location) | ||
.revs(1) | ||
.then(([firstRev]) => { | ||
if (!firstRev) { | ||
console.warn('😵 Cannot get git history of ' + book.location) | ||
return book | ||
} else { | ||
return { ...book, added: firstRev.commit.date() } | ||
} | ||
}) | ||
) | ||
) | ||
.then(stats => stats | ||
.filter(stat => stat) | ||
.reduce((feed, book) => { | ||
feed.addItem({ | ||
id: book.objectID, | ||
date: book.added, | ||
link: "http://mustread.tech/books/isbn/" + book.objectID, | ||
title: "Must-read book: " + book.title, | ||
description: book.description.slice(0, 256) + "..." | ||
}) | ||
feed.options.updated = max(feed.items, item => item.date) | ||
return feed | ||
}, emptyFeed)) | ||
.then(feed => feed.atom1()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const dayjs = require('dayjs') | ||
const GitFile = require('./classes/GitFile') | ||
|
||
const commitMonth = rev => dayjs(rev.commit.date()).format('MMMM') | ||
|
||
module.exports = books => | ||
Promise | ||
.all(books | ||
.map(book => | ||
new GitFile(book.location) | ||
.revs(1) | ||
.then(([firstRev]) => { | ||
let isbn = book.objectID | ||
if (!firstRev) { | ||
console.warn('😵 Cannot get git history of ' + book.location) | ||
return undefined | ||
} else { | ||
return { isbn: isbn.toString(), month: commitMonth(firstRev) } | ||
} | ||
}) | ||
) | ||
) | ||
.then(stats => stats | ||
.filter(stat => stat) | ||
.reduce((acc, curr) => | ||
Object.assign(acc, {[curr.month]: [curr.isbn].concat(acc[curr.month] || [])}), {} | ||
)) | ||
.then(JSON.stringify) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,15 +5,18 @@ | |
"author": "Eduards Sizovs <[email protected]>", | ||
"private": true, | ||
"scripts": { | ||
"start": "babel . --out-dir ./build --ignore 'node_modules' && node ./build/indexAll.js" | ||
"start": "babel . --out-dir ./build --ignore 'node_modules','build' && node ./build/indexAll.js" | ||
}, | ||
"dependencies": { | ||
"@google-cloud/storage": "^2.3.4", | ||
"algoliasearch": "^3.32.0", | ||
"axios": "^0.18.0", | ||
"babel-register": "^6.26.0", | ||
"cheerio": "^1.0.0-rc.2", | ||
"dayjs": "^1.7.8", | ||
"feed": "^2.0.2", | ||
"js-yaml": "^3.12.0", | ||
"nodegit": "^0.23.0", | ||
"xml-js": "^1.6.8" | ||
}, | ||
"devDependencies": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const { Storage } = require('@google-cloud/storage'); | ||
|
||
const BUCKET_NAME = 'static.mustread.tech' | ||
|
||
const storage = new Storage({ projectId: 'mustread-tech' }) | ||
const bucket = storage.bucket(BUCKET_NAME) | ||
|
||
const saveFile = async (name, content, contentType) => { | ||
const file = bucket.file(name) | ||
await file.save(content) | ||
await file.setMetadata({ cacheControl: 'no-cache', contentType: contentType, contentDisposition: `inline; filename="${name}"` }) | ||
await file.makePublic() | ||
} | ||
|
||
module.exports = async (stats, rss) => { | ||
|
||
const bucketExists = await bucket.exists() | ||
if (!bucketExists) { | ||
await bucket.create() | ||
} | ||
|
||
await bucket.setMetadata({ | ||
cors: [ | ||
{ | ||
origin: ['*'], | ||
method: ['*'], | ||
responseHeader: ["Content-Type"], | ||
maxAgeSeconds: 3600 | ||
} | ||
] | ||
}) | ||
|
||
await saveFile('stats.json', stats, 'application/json') | ||
await saveFile('rss.xml', rss, 'application/xml') | ||
} |
Oops, something went wrong.