Skip to content

Commit

Permalink
add Sandi's Bottles of OOP
Browse files Browse the repository at this point in the history
  • Loading branch information
sizovs committed Jan 1, 2019
1 parent b5d6733 commit f0ad9c6
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 11 deletions.
7 changes: 7 additions & 0 deletions books/99 Bottles of OOP.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
book:
isbn: 9781944823009
grid: 31183020
tags:
- coding
- ruby
4 changes: 2 additions & 2 deletions classes/GitFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ class GitFile {
constructor(location) {
this.location = location
}
revs(count, order = Git.Revwalk.SORT.REVERSE) {
revs(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)})
return walker.fileHistoryWalk(this.location, 1000)})
}
}

Expand Down
5 changes: 2 additions & 3 deletions fetch/goodreads.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ const toBook = it => ({
link: it.link._cdata,
authors: alwaysArray(it.authors.author).map($ => $.name._text)
})

module.exports = isbn => axios
.get(`https://www.goodreads.com/book/isbn/${isbn}?key=${process.env.GOODREADS_API_KEY}`)
module.exports = (isbn, grid) => axios
.get(`https://www.goodreads.com/book/${grid ? 'show/' + grid : 'isbn/' + isbn }?key=${process.env.GOODREADS_API_KEY}`)
.then(response => convert.xml2js(response.data, { compact: true, nativeType: true, ignoreDeclaration: true }))
.then(body => body.GoodreadsResponse.book)
.then(toBook)
6 changes: 3 additions & 3 deletions generateFeed.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = books =>
.all(books
.map(book =>
new GitFile(book.location)
.revs(1)
.revs()
.then(([firstRev]) => {
if (!firstRev) {
console.warn('😵 Cannot get git history of ' + book.location)
Expand All @@ -33,9 +33,9 @@ module.exports = books =>
.filter(stat => stat)
.reduce((feed, book) => {
feed.addItem({
id: book.objectID,
id: "http://mustread.tech/books/isbn/" + book.objectID,
date: book.added,
link: "http://mustread.tech/books/isbn/" + book.objectID,
link: "http://mustread.tech/books/isbn/" + book.objectID,
title: "Must-read book: " + book.title,
description: book.description.slice(0, 256) + "..."
})
Expand Down
2 changes: 1 addition & 1 deletion generateStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = books =>
.all(books
.map(book =>
new GitFile(book.location)
.revs(1)
.revs()
.then(([firstRev]) => {
let isbn = book.objectID
if (!firstRev) {
Expand Down
4 changes: 2 additions & 2 deletions indexAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@

const outIfNeeded = c => true
const booksInFuture = contributedFiles.filter(outIfNeeded).map(async contribution => {
const { isbn, description, tags } = contribution.book
const { isbn, grid, description, tags } = contribution.book
try {

const goodreads = await require('./fetch/goodreads')(isbn)
const goodreads = await require('./fetch/goodreads')(isbn, grid)
const gbooks = await require('./fetch/gbooks')(isbn)
const cover = await require('./fetch/cover')(goodreads.link)

Expand Down

0 comments on commit f0ad9c6

Please sign in to comment.