fix: generate proper github-matching URL slugs for methods

This commit is contained in:
Zeke Sikelianos 2018-06-18 13:31:57 -07:00
Родитель 1ed980786b
Коммит 5526a44934
3 изменённых файлов: 11 добавлений и 4 удалений

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

@ -1,5 +1,6 @@
const AlgoliaIndex = require('../lib/algolia-index')
const apis = require('../electron-api.json')
const slugger = new (require('github-slugger'))()
module.exports = new AlgoliaIndex('apis', getRecords())
@ -16,8 +17,8 @@ function getRecords () {
method.apiType = 'staticMethod'
method.fullSignature = `${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}`
method.slug = slugger.slug(method.fullSignature)
method.url = `https://electronjs.org/docs/api/${api.slug}#${method.slug}`
delete method.signature
records.push(method)
})
@ -27,8 +28,8 @@ function getRecords () {
method.apiType = 'instanceMethod'
method.fullSignature = `${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}`
method.slug = slugger.slug(method.fullSignature)
method.url = `https://electronjs.org/docs/api/${api.slug}#${method.slug}`
delete method.signature
records.push(method)
})

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

@ -25,6 +25,7 @@
"electron-apps": "^1.2899.0",
"electron-i18n": "^1.86.0",
"electron-npm-packages": "^4.1.2",
"github-slugger": "^1.2.0",
"instantsearch.js": "^2.7.4",
"is-url": "^1.2.4",
"local-repl": "^4.0.0",

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

@ -38,6 +38,11 @@ test('electron-search', t => {
const tldrThreshold = 95
t.ok(apisWithTldrs.length / apis.length * 100 > tldrThreshold, `At least ${tldrThreshold}% of APIs have a tldr`)
// method URLs should match the slugs generated by github.com (and hubdown)
const apiUrls = apis.map(api => api.url)
const expectedUrl = 'https://electronjs.org/docs/api/web-request#webrequestonheadersreceivedfilter-listener'
t.ok(apiUrls.includes(expectedUrl), `API with URL exists: ${expectedUrl}`)
// Tutorials
// ----------------------------------------------------------------------
const tutorials = indices.tutorials.records