write objectID at the top of each record

This commit is contained in:
Zeke Sikelianos 2018-05-20 22:02:34 -07:00
Родитель 2334a82e93
Коммит 4a3c445691
8 изменённых файлов: 75 добавлений и 7 удалений

Просмотреть файл

@ -5,13 +5,14 @@ module.exports = new AlgoliaIndex('apps', getRecords())
function getRecords () {
return apps.map(app => {
app.objectID = `app-${app.slug}`
// remove large fields to avoid going over algolia plan limits
delete app.latestRelease
delete app.readmeCleaned
delete app.readmeOriginal
return app
return Object.assign(
{objectID: `app-${app.slug}`},
app
)
})
}

Просмотреть файл

@ -1,11 +1,30 @@
const {pick} = require('lodash')
const packages = require('electron-npm-packages')
const AlgoliaIndex = require('../lib/algolia-index')
const props = 'name description sourcerank repository keywords license homepage owners created modified dependencies devDependencies scripts'.split(' ')
module.exports = new AlgoliaIndex('packages', getRecords())
function getRecords () {
return packages.map(pkg => {
pkg.objectID = `package-${pkg.name}`
pkg = Object.assign(
{objectID: `package-${pkg.name}`},
pick(pkg, props)
)
if (pkg.repository && pkg.repository.https_url) {
pkg.repository = pkg.repository.https_url
}
// algolia doesn't search on keys, so save all dep names in a searchable array
if (pkg.dependencies) {
pkg.depNames = Object.keys(pkg.dependencies)
}
if (pkg.devDependencies) {
pkg.devDepNames = Object.keys(pkg.devDependencies)
}
return pkg
})
}

Просмотреть файл

@ -12,11 +12,20 @@ function getRecords () {
const objectID = `tutorial-${slug}`
const html = sections.map(section => section.html).join('\n\n')
const body = cheerio.load(html).text()
// ignore files that have been renamed
if (!title && body.startsWith('Moved to')) return
if (slug === 'README') return
const url = `https://electronjs.org/docs/tutorial/${slug}`
return {objectID, title, githubUrl, url, slug, body}
return {
objectID,
title,
githubUrl,
url,
slug,
body
}
})
.compact() // remove nulls from early returns above
.value()

Просмотреть файл

@ -7,7 +7,10 @@
"author": "zeke",
"license": "MIT",
"scripts": {
"echo": "script/echo.js",
"preupload": "npm run test",
"upload": "script/upload.js",
"update": "script/update.sh",
"test": "tape test.js | tap-spec && standard --fix",
"lint": "standard --fix",
"start": "budo demo.js --live --no-debug --open --css demo.css",

3
script/echo.js Executable file
Просмотреть файл

@ -0,0 +1,3 @@
#!/usr/bin/env node
process.stdout.write(JSON.stringify(require('../indices'), null, 2))

29
script/update.sh Executable file
Просмотреть файл

@ -0,0 +1,29 @@
#!/usr/bin/env bash
set -x # print commands before execution
set -o errexit # always exit on error
set -o pipefail # honor exit codes when piping
set -o nounset # fail on unset variables
# bootstrap
git clone "https://github.com/electron/algolia-search-index" project
cd project
npm install
# update stuff
npm update electron-apps
npm update electron-i18n
npm update electron-npm-packages
# bail if nothing changed
[[ `git status --porcelain` ]] || exit
# upload to algolia
npm run upload
# save changes in git
git add .
git config user.email electron@github.com
git config user.name electron-bot
git commit -am "update data sources"
git push origin master --follow-tags

Просмотреть файл

@ -4,4 +4,8 @@ require('dotenv-safe').load()
const indices = require('../indices')
console.log(indices)
for (const key in indices) {
const index = indices[key]
console.log(`Uploading index: ${index.name}`)
index.upload()
}

Просмотреть файл

@ -56,7 +56,7 @@ test('electron-search', t => {
if (!pkg.name) console.log(pkg)
t.equal(typeof pkg.name, 'string', `${pkg.name} has a name`)
// t.ok(isURL(pkg.githubUrl), `${pkg.title} has a valid GitHub URL`)
// t.ok(isURL(pkg.url), `${pkg.title} has a valid website URL`)
// t.ok(isURL(pkg.repository), `${pkg.title} has a valid repository`)
})
// Repos