Add gutenberg utility functions

context-store
Alfred Melch 5 years ago
parent 8ce324cd04
commit e98ea6eb87

@ -0,0 +1,23 @@
import Axios from 'axios'
export async function search(searchTerm, maxResults = Infinity) {
const regex = new RegExp(searchTerm, 'i')
const result = []
const data = await import('../../data/gutenberg.json').then(
module => module.default
)
for (let entry of data) {
if (regex.test(entry.title[0]) || regex.test(entry.author[0])) {
result.push(entry)
}
if (result.length >= maxResults) break
}
return result
}
export async function getBook(bookId) {
const url = `https://gutenberg.muperfredi.de/texts/${bookId}/stripped-body`
const text = await Axios.get(url).then(res => res.data.body)
return text
}
Loading…
Cancel
Save