Make search work with category names (#4103)

This commit is contained in:
Pierre-Yves B
2019-10-02 20:03:59 +01:00
committed by GitHub
parent a865b81acb
commit 157a6180b2
14 changed files with 37 additions and 37 deletions

View File

@@ -2,6 +2,7 @@
const Joi = require('@hapi/joi')
const pathToRegexp = require('path-to-regexp')
const categories = require('../../services/categories')
const coalesceBadge = require('./coalesce-badge')
const { makeFullUrl } = require('./route')
@@ -154,7 +155,9 @@ function transformExample(inExample, index, ServiceClass) {
style: style === 'flat' ? undefined : style,
namedLogo,
},
keywords,
keywords: keywords.concat(
categories.find(c => c.id === ServiceClass.category).keywords
),
documentation: documentation ? { __html: documentation } : undefined,
}
}

View File

@@ -84,6 +84,7 @@ test(transformExample, function() {
defaultBadgeData: {
label: 'downloads',
},
category: 'platform-support',
}
given(
@@ -109,7 +110,7 @@ test(transformExample, function() {
namedLogo: undefined,
style: undefined,
},
keywords: ['hello'],
keywords: ['hello', 'platform'],
documentation: undefined,
})
@@ -135,7 +136,7 @@ test(transformExample, function() {
namedLogo: undefined,
style: undefined,
},
keywords: ['hello'],
keywords: ['hello', 'platform'],
documentation: undefined,
})
@@ -162,7 +163,7 @@ test(transformExample, function() {
namedLogo: undefined,
style: undefined,
},
keywords: ['hello'],
keywords: ['hello', 'platform'],
documentation: undefined,
})
})

View File

@@ -66,6 +66,7 @@ const serviceDefinitionExport = Joi.object({
Joi.object({
id: Joi.string().required(),
name: Joi.string().required(),
keywords: arrayOfStrings,
})
)
.required(),

View File

@@ -324,7 +324,7 @@ module.exports = class GemVersion extends BaseJsonService {
- `namedParams`: Provide a valid example of params we can substitute into
the pattern. In this case we need a valid ruby gem, so we've picked [formatador](https://rubygems.org/gems/formatador).
- `staticPreview`: On the index page we want to show an example badge, but for performance reasons we want that example to be generated without making an API call. `staticPreview` should be populated by calling our `render()` method with some valid data.
- `keywords`: If we want to provide additional keywords other than the title, we can add them here. This helps users to search for relevant badges.
- `keywords`: If we want to provide additional keywords other than the title and the category, we can add them here. This helps users to search for relevant badges.
Save, run `npm start`, and you can see it [locally](http://127.0.0.1:3000/).

View File

@@ -4,7 +4,7 @@ import { findCategory, getDefinitionsForCategory } from '.'
describe('Service definition helpers', function() {
test(findCategory, () => {
given('build').expect({ id: 'build', name: 'Build' })
given('build').expect({ id: 'build', name: 'Build', keywords: ['build'] })
given('foo').expect(undefined)
})

View File

@@ -5,6 +5,7 @@ import definitions from '../../../service-definitions.yml'
export interface Category {
id: string
name: string
keywords: string[]
}
export interface ExampleSignature {

View File

@@ -1,21 +1,25 @@
'use strict'
module.exports = [
{ id: 'build', name: 'Build' },
{ id: 'coverage', name: 'Code Coverage' },
{ id: 'analysis', name: 'Analysis' },
{ id: 'chat', name: 'Chat' },
{ id: 'dependencies', name: 'Dependencies' },
{ id: 'size', name: 'Size' },
{ id: 'downloads', name: 'Downloads' },
{ id: 'funding', name: 'Funding' },
{ id: 'issue-tracking', name: 'Issue Tracking' },
{ id: 'license', name: 'License' },
{ id: 'rating', name: 'Rating' },
{ id: 'social', name: 'Social' },
{ id: 'version', name: 'Version' },
{ id: 'platform-support', name: 'Platform & Version Support' },
{ id: 'monitoring', name: 'Monitoring' },
{ id: 'activity', name: 'Activity' },
{ id: 'other', name: 'Other' },
{ id: 'build', name: 'Build', keywords: ['build'] },
{ id: 'coverage', name: 'Code Coverage', keywords: ['coverage'] },
{ id: 'analysis', name: 'Analysis', keywords: ['analysis'] },
{ id: 'chat', name: 'Chat', keywords: ['chat'] },
{ id: 'dependencies', name: 'Dependencies', keywords: ['dependencies'] },
{ id: 'size', name: 'Size', keywords: ['size'] },
{ id: 'downloads', name: 'Downloads', keywords: ['downloads'] },
{ id: 'funding', name: 'Funding', keywords: ['funding'] },
{ id: 'issue-tracking', name: 'Issue Tracking', keywords: ['issue'] },
{ id: 'license', name: 'License', keywords: ['license'] },
{ id: 'rating', name: 'Rating', keywords: ['rating'] },
{ id: 'social', name: 'Social', keywords: ['social'] },
{ id: 'version', name: 'Version', keywords: ['version'] },
{
id: 'platform-support',
name: 'Platform & Version Support',
keywords: ['platform'],
},
{ id: 'monitoring', name: 'Monitoring', keywords: ['monitoring'] },
{ id: 'activity', name: 'Activity', keywords: ['activity'] },
{ id: 'other', name: 'Other', keywords: [] },
]

View File

@@ -22,8 +22,6 @@ const releaseArraySchema = Joi.alternatives().try(
Joi.array().length(0)
)
const keywords = ['github download']
module.exports = class GithubDownloads extends GithubAuthV3Service {
static get category() {
return 'downloads'
@@ -50,7 +48,6 @@ module.exports = class GithubDownloads extends GithubAuthV3Service {
downloadCount: 857000,
}),
documentation,
keywords,
},
{
title: 'GitHub Releases',
@@ -66,7 +63,6 @@ module.exports = class GithubDownloads extends GithubAuthV3Service {
downloadCount: 27000,
}),
documentation,
keywords,
},
{
title: 'GitHub Pre-Releases',
@@ -82,7 +78,6 @@ module.exports = class GithubDownloads extends GithubAuthV3Service {
downloadCount: 2000,
}),
documentation,
keywords,
},
{
title: 'GitHub Releases (by Release)',
@@ -98,7 +93,6 @@ module.exports = class GithubDownloads extends GithubAuthV3Service {
downloadCount: 490000,
}),
documentation,
keywords,
},
{
title: 'GitHub Releases (by Asset)',
@@ -115,7 +109,6 @@ module.exports = class GithubDownloads extends GithubAuthV3Service {
downloadCount: 3000,
}),
documentation,
keywords,
},
{
title: 'GitHub Pre-Releases (by Asset)',
@@ -132,7 +125,6 @@ module.exports = class GithubDownloads extends GithubAuthV3Service {
downloadCount: 237,
}),
documentation,
keywords,
},
]
}

View File

@@ -6,7 +6,7 @@ const { age: ageColor } = require('../color-formatters')
const { GithubAuthV3Service } = require('./github-auth-service')
const { documentation, errorMessagesFor } = require('./github-helpers')
const commonExampleAttrs = {
keywords: ['activity', 'latest'],
keywords: ['latest'],
documentation,
}

View File

@@ -32,7 +32,6 @@ module.exports = class GithubLicense extends GithubAuthV3Service {
message: 'MIT',
color: 'green',
},
keywords: ['license'],
documentation,
},
]

View File

@@ -64,7 +64,6 @@ module.exports = class JiraSprint extends BaseJsonService {
numTotalIssues: 28,
}),
documentation,
keywords: ['issues'],
},
]
}

View File

@@ -23,7 +23,7 @@ module.exports = class VaadinDirectoryRatingCount extends BaseVaadinDirectorySer
pattern: 'rating-count/:packageName',
namedParams: { packageName: 'vaadinvaadin-grid' },
staticPreview: this.render({ ratingCount: 6 }),
keywords: ['vaadin-directory', 'rating-count', 'rating count'],
keywords: ['vaadin-directory', 'rating-count'],
},
]
}

View File

@@ -23,7 +23,7 @@ module.exports = class VaadinDirectoryRating extends BaseVaadinDirectoryService
pattern: ':format(stars|rating)/:packageName',
namedParams: { format: 'rating', packageName: 'vaadinvaadin-grid' },
staticPreview: this.render({ format: 'rating', score: 4.75 }),
keywords: ['vaadin-directory', 'rating'],
keywords: ['vaadin-directory'],
},
]
}

View File

@@ -22,7 +22,7 @@ module.exports = class VaadinDirectoryVersion extends BaseVaadinDirectoryService
pattern: 'v/:packageName',
namedParams: { packageName: 'vaadinvaadin-grid' },
staticPreview: renderVersionBadge({ version: 'v5.3.0-alpha4' }),
keywords: ['vaadin-directory', 'version', 'latest version'],
keywords: ['vaadin-directory', 'latest'],
},
]
}