add tutorials to the search index
This commit is contained in:
Родитель
05f6328bc4
Коммит
7e6b4ee518
|
@ -0,0 +1,35 @@
|
|||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
padding: 50px;
|
||||
font-family: 'helvetica neue', helvetica, arial;
|
||||
}
|
||||
|
||||
#search-box input {
|
||||
padding: 10px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.ais-hits--item {
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.ais-hits--item em {
|
||||
background-color: yellow;
|
||||
}
|
||||
|
||||
.ais-search-box--magnifier {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.ais-search-box--reset {
|
||||
top: 12px;
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
border: none;
|
||||
position: absolute;
|
||||
right: 10px;
|
||||
opacity: 0.2;
|
||||
}
|
38
demo.js
38
demo.js
|
@ -4,44 +4,6 @@ document.title = 'Electron Search'
|
|||
|
||||
const $main = html`
|
||||
<main>
|
||||
<style>
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
padding: 50px;
|
||||
font-family: 'helvetica neue', helvetica, arial;
|
||||
}
|
||||
|
||||
#search-box input {
|
||||
padding: 10px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.ais-hits--item {
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.ais-hits--item em {
|
||||
background-color: yellow;
|
||||
}
|
||||
|
||||
.ais-search-box--magnifier {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.ais-search-box--reset {
|
||||
top: 12px;
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
border: none;
|
||||
position: absolute;
|
||||
right: 10px;
|
||||
opacity: 0.2;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div id="search-box"></div>
|
||||
<div id="refinement-list"></div>
|
||||
<div id="hits"></div>
|
||||
|
|
1973
index.json
1973
index.json
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -0,0 +1,67 @@
|
|||
const apis = require('../electron-api.json')
|
||||
const results = []
|
||||
|
||||
apis.forEach(api => {
|
||||
// TODO constructorMethod
|
||||
|
||||
const staticMethods = api.staticMethods || []
|
||||
staticMethods.forEach(method => {
|
||||
method.type = 'api'
|
||||
method.apiType = 'staticMethod'
|
||||
method.title = `${api.name}.${method.name}${method.signature}`
|
||||
method.tldr = getTLDR(method)
|
||||
const slug = method.name.replace(/\W/g, '').toLowerCase()
|
||||
method.url = `https://electronjs.org/docs/api/${api.slug}#${api.slug}${slug}`
|
||||
delete method.signature
|
||||
results.push(method)
|
||||
})
|
||||
|
||||
const instanceMethods = api.instanceMethods || []
|
||||
instanceMethods.forEach(method => {
|
||||
method.type = 'api'
|
||||
method.apiType = 'instanceMethod'
|
||||
method.title = `${api.instanceName}.${method.name}${method.signature}`
|
||||
method.tldr = getTLDR(method)
|
||||
const slug = method.name.replace(/\W/g, '').toLowerCase()
|
||||
method.url = `https://electronjs.org/docs/api/${api.slug}#${api.slug}${slug}`
|
||||
delete method.signature
|
||||
results.push(method)
|
||||
})
|
||||
|
||||
const events = api.events || []
|
||||
events.forEach(event => {
|
||||
event.type = 'api'
|
||||
event.apiType = 'event'
|
||||
event.title = `${api.name}.on('${event.name}')`
|
||||
event.url = `https://electronjs.org/docs/api/${api.slug}#event-${event.name}`
|
||||
event.tldr = getTLDR(event)
|
||||
results.push(event)
|
||||
})
|
||||
|
||||
const instanceEvents = api.instanceEvents || []
|
||||
instanceEvents.forEach(event => {
|
||||
event.type = 'api'
|
||||
event.apiType = 'event'
|
||||
event.title = `${api.instanceName}.on('${event.name}')`
|
||||
event.url = `https://electronjs.org/docs/api/${api.slug}#event-${event.name}`
|
||||
event.tldr = getTLDR(event)
|
||||
results.push(event)
|
||||
})
|
||||
})
|
||||
|
||||
function getTLDR (api) {
|
||||
const { description, returns } = api
|
||||
|
||||
if (!description && returns && returns.description) {
|
||||
return (
|
||||
'Returns ' +
|
||||
returns.description.charAt(0).toLowerCase() +
|
||||
returns.description.slice(1)
|
||||
)
|
||||
}
|
||||
|
||||
if (typeof description !== 'string' || !description.length) return null
|
||||
return description.split('. ')[0] + '.'
|
||||
}
|
||||
|
||||
module.exports = results
|
|
@ -0,0 +1,16 @@
|
|||
const {chain} = require('lodash')
|
||||
const cheerio = require('cheerio')
|
||||
|
||||
module.exports = chain(Object.values(require('electron-i18n').docs['en-US']))
|
||||
.filter(tutorial => !tutorial.isApiDoc && !tutorial.isApiStructureDoc)
|
||||
.map(tutorial => {
|
||||
const {title, githubUrl, slug, sections} = tutorial
|
||||
const type = 'tutorial'
|
||||
const html = sections.map(section => section.html).join('\n\n')
|
||||
const body = cheerio.load(html).text()
|
||||
if (!title && body.startsWith('Moved to')) return
|
||||
const url = `https://electronjs.org/docs/tutorial/${slug}`
|
||||
return {type, title, githubUrl, url, slug, body}
|
||||
})
|
||||
.compact() // remove nulls
|
||||
.value()
|
|
@ -11,18 +11,21 @@
|
|||
"pretest": "npm run build",
|
||||
"test": "tape test.js | tap-spec && standard --fix",
|
||||
"lint": "standard --fix",
|
||||
"demo": "budo demo.js --live --no-debug --open",
|
||||
"demo": "budo demo.js --live --no-debug --open --css demo.css",
|
||||
"repl": "local-repl"
|
||||
},
|
||||
"devDependencies": {
|
||||
"budo": "^11.2.0",
|
||||
"cheerio": "^1.0.0-rc.2",
|
||||
"electron-i18n": "^1.86.0",
|
||||
"instantsearch.js": "^2.7.4",
|
||||
"is-url": "^1.2.4",
|
||||
"local-repl": "^4.0.0",
|
||||
"lodash": "^4.17.10",
|
||||
"nanohtml": "^1.2.4",
|
||||
"prettier-standard": "^8.0.1",
|
||||
"standard": "^11.0.1",
|
||||
"tap-spec": "^4.1.1",
|
||||
"tape": "^4.9.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,65 +1,8 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
const apis = require('../electron-api.json')
|
||||
const results = []
|
||||
|
||||
apis.forEach(api => {
|
||||
// TODO constructorMethod
|
||||
|
||||
const staticMethods = api.staticMethods || []
|
||||
staticMethods.forEach(method => {
|
||||
method.title = `${api.name}.${method.name}${method.signature}`
|
||||
method.type = 'staticMethod'
|
||||
method.tldr = getTLDR(method)
|
||||
const slug = method.name.replace(/\W/g, '').toLowerCase()
|
||||
method.url = `https://electronjs.org/docs/api/${api.slug}#${api.slug}${slug}`
|
||||
delete method.signature
|
||||
results.push(method)
|
||||
})
|
||||
|
||||
const instanceMethods = api.instanceMethods || []
|
||||
instanceMethods.forEach(method => {
|
||||
method.title = `${api.instanceName}.${method.name}${method.signature}`
|
||||
method.type = 'instanceMethod'
|
||||
method.tldr = getTLDR(method)
|
||||
const slug = method.name.replace(/\W/g, '').toLowerCase()
|
||||
method.url = `https://electronjs.org/docs/api/${api.slug}#${api.slug}${slug}`
|
||||
delete method.signature
|
||||
results.push(method)
|
||||
})
|
||||
|
||||
const events = api.events || []
|
||||
events.forEach(event => {
|
||||
event.title = `${api.name}.on('${event.name}')`
|
||||
event.type = 'event'
|
||||
event.url = `https://electronjs.org/docs/api/${api.slug}#event-${event.name}`
|
||||
event.tldr = getTLDR(event)
|
||||
results.push(event)
|
||||
})
|
||||
|
||||
const instanceEvents = api.instanceEvents || []
|
||||
instanceEvents.forEach(event => {
|
||||
event.title = `${api.instanceName}.on('${event.name}')`
|
||||
event.type = 'event'
|
||||
event.url = `https://electronjs.org/docs/api/${api.slug}#event-${event.name}`
|
||||
event.tldr = getTLDR(event)
|
||||
results.push(event)
|
||||
})
|
||||
})
|
||||
const {chain} = require('lodash')
|
||||
const apis = require('../lib/electron-apis')
|
||||
const tutorials = require('../lib/tutorials.js')
|
||||
const results = chain([apis, tutorials]).flatten().value()
|
||||
|
||||
process.stdout.write(JSON.stringify(results, null, 2))
|
||||
|
||||
function getTLDR (api) {
|
||||
const { description, returns } = api
|
||||
|
||||
if (!description && returns && returns.description) {
|
||||
return (
|
||||
'Returns ' +
|
||||
returns.description.charAt(0).toLowerCase() +
|
||||
returns.description.slice(1)
|
||||
)
|
||||
}
|
||||
|
||||
if (typeof description !== 'string' || !description.length) return null
|
||||
return description.split('. ')[0] + '.'
|
||||
}
|
||||
|
|
39
test.js
39
test.js
|
@ -1,12 +1,22 @@
|
|||
const apis = require('.')
|
||||
const entries = require('.')
|
||||
const test = require('tape')
|
||||
// const isURL = require('is-url')
|
||||
const isURL = require('is-url')
|
||||
const types = ['api', 'tutorial']
|
||||
|
||||
test('electron-search', t => {
|
||||
t.ok(Array.isArray(apis), 'is an array')
|
||||
t.ok(apis.length > 5, 'with hella entries')
|
||||
// All Entries
|
||||
// ----------------------------------------------------------------------
|
||||
t.ok(Array.isArray(entries), 'is an array')
|
||||
t.ok(entries.length > 5, 'with hella entries')
|
||||
entries.forEach(entry => {
|
||||
t.ok(types.includes(entry.type), `${entry.title} has a known type`)
|
||||
})
|
||||
|
||||
// console.log(apis.map(api => api.title))
|
||||
// APIs
|
||||
// ----------------------------------------------------------------------
|
||||
const apis = entries.filter(entry => entry.type === 'api')
|
||||
|
||||
t.ok(apis.length > 5, 'lots of APIs')
|
||||
|
||||
let staticMethod = apis.find(api => api.title === 'Menu.getApplicationMenu()')
|
||||
t.equal(staticMethod.url, 'https://electronjs.org/docs/api/menu#menugetapplicationmenu', 'sets proper URL on static methods')
|
||||
|
@ -20,7 +30,22 @@ test('electron-search', t => {
|
|||
// t.ok(isURL(api.url), `${api.title} has a valid URL`)
|
||||
})
|
||||
|
||||
// Tutorials
|
||||
// ----------------------------------------------------------------------
|
||||
const tutorials = entries.filter(entry => entry.type === 'tutorial')
|
||||
|
||||
tutorials.forEach(tutorial => {
|
||||
if (!tutorial.title) console.log(tutorial)
|
||||
t.equal(typeof tutorial.title, 'string', `${tutorial.title} has a title`)
|
||||
t.equal(typeof tutorial.body, 'string', `${tutorial.title} has a body`)
|
||||
t.ok(isURL(tutorial.githubUrl), `${tutorial.title} has a valid GitHub URL`)
|
||||
})
|
||||
|
||||
// Packages
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
// Repos
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
// https://electronjs.org/docs/api/browser-window#event-page-title-updated
|
||||
|
|
Загрузка…
Ссылка в новой задаче