Switch themes to minimo

This commit is contained in:
Dave Gallant
2021-09-06 11:55:05 -04:00
parent 75f9797c91
commit 4ff7aec7c1
302 changed files with 17841 additions and 607 deletions

View File

@@ -0,0 +1,42 @@
const path = require('path')
const algoliasearch = require('algoliasearch')
const glob = require('glob')
const client = algoliasearch(
process.env.ALGOLIA_APP_ID,
process.env.ALGOLIA_ADMIN_API_KEY
)
const indexName = process.env.ALGOLIA_INDEX_NAME || 'minimo_site'
const publicDir = path.resolve(process.argv[2] || 'public')
const objectsPaths = glob.sync('**/search/index.json', {
cwd: publicDir,
absolute: true
})
const indicesInfo = objectsPaths.map(objectsPath => ({
path: objectsPath,
name: `${indexName}${objectsPath
.slice(publicDir.length, -'/search/index.json'.length)
.replace('/', '_')}`
}))
indicesInfo.forEach(indexInfo => {
let objects = require(indexInfo.path)
objects.forEach(object => {
object.objectID = object.href
})
let index = client.initIndex(indexInfo.name)
index.addObjects(objects, (err, _content) => {
if (err) console.error(err.toString())
else
console.log(
`Algolia Index Generated for: ${indexInfo.path.replace(publicDir, '')}`
)
})
})

View File

@@ -0,0 +1,45 @@
const fs = require('fs')
const path = require('path')
const glob = require('glob')
const lunr = require('lunr')
const publicDir = path.resolve(process.argv[2] || 'public')
const documentsPaths = glob.sync('**/search/index.json', {
cwd: publicDir,
absolute: true
})
documentsPaths.forEach(documentsPath => {
let documents = require(documentsPath)
let idx = lunr(function() {
this.ref('href')
this.field('title', { boost: 10 })
this.field('content')
documents.forEach(doc => {
this.add(doc)
})
})
let pageTitles = documents.reduce(
(pages, doc) => ({ ...pages, [doc.href]: doc.title }),
{}
)
fs.writeFile(
documentsPath.replace('index.json', 'lunr_idx.js'),
`window.lunr_idx=${JSON.stringify(
idx
)}\nwindow.page_titles=${JSON.stringify(pageTitles)}`,
err => {
if (err) console.error(err)
else
console.log(
`Lunr.js Index Generated for: ${documentsPath.replace(publicDir, '')}`
)
}
)
})