Make search work with category names (#4103)
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
const Joi = require('@hapi/joi')
|
const Joi = require('@hapi/joi')
|
||||||
const pathToRegexp = require('path-to-regexp')
|
const pathToRegexp = require('path-to-regexp')
|
||||||
|
const categories = require('../../services/categories')
|
||||||
const coalesceBadge = require('./coalesce-badge')
|
const coalesceBadge = require('./coalesce-badge')
|
||||||
const { makeFullUrl } = require('./route')
|
const { makeFullUrl } = require('./route')
|
||||||
|
|
||||||
@@ -154,7 +155,9 @@ function transformExample(inExample, index, ServiceClass) {
|
|||||||
style: style === 'flat' ? undefined : style,
|
style: style === 'flat' ? undefined : style,
|
||||||
namedLogo,
|
namedLogo,
|
||||||
},
|
},
|
||||||
keywords,
|
keywords: keywords.concat(
|
||||||
|
categories.find(c => c.id === ServiceClass.category).keywords
|
||||||
|
),
|
||||||
documentation: documentation ? { __html: documentation } : undefined,
|
documentation: documentation ? { __html: documentation } : undefined,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ test(transformExample, function() {
|
|||||||
defaultBadgeData: {
|
defaultBadgeData: {
|
||||||
label: 'downloads',
|
label: 'downloads',
|
||||||
},
|
},
|
||||||
|
category: 'platform-support',
|
||||||
}
|
}
|
||||||
|
|
||||||
given(
|
given(
|
||||||
@@ -109,7 +110,7 @@ test(transformExample, function() {
|
|||||||
namedLogo: undefined,
|
namedLogo: undefined,
|
||||||
style: undefined,
|
style: undefined,
|
||||||
},
|
},
|
||||||
keywords: ['hello'],
|
keywords: ['hello', 'platform'],
|
||||||
documentation: undefined,
|
documentation: undefined,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -135,7 +136,7 @@ test(transformExample, function() {
|
|||||||
namedLogo: undefined,
|
namedLogo: undefined,
|
||||||
style: undefined,
|
style: undefined,
|
||||||
},
|
},
|
||||||
keywords: ['hello'],
|
keywords: ['hello', 'platform'],
|
||||||
documentation: undefined,
|
documentation: undefined,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -162,7 +163,7 @@ test(transformExample, function() {
|
|||||||
namedLogo: undefined,
|
namedLogo: undefined,
|
||||||
style: undefined,
|
style: undefined,
|
||||||
},
|
},
|
||||||
keywords: ['hello'],
|
keywords: ['hello', 'platform'],
|
||||||
documentation: undefined,
|
documentation: undefined,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ const serviceDefinitionExport = Joi.object({
|
|||||||
Joi.object({
|
Joi.object({
|
||||||
id: Joi.string().required(),
|
id: Joi.string().required(),
|
||||||
name: Joi.string().required(),
|
name: Joi.string().required(),
|
||||||
|
keywords: arrayOfStrings,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.required(),
|
.required(),
|
||||||
|
|||||||
@@ -324,7 +324,7 @@ module.exports = class GemVersion extends BaseJsonService {
|
|||||||
- `namedParams`: Provide a valid example of params we can substitute into
|
- `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).
|
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.
|
- `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/).
|
Save, run `npm start`, and you can see it [locally](http://127.0.0.1:3000/).
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { findCategory, getDefinitionsForCategory } from '.'
|
|||||||
|
|
||||||
describe('Service definition helpers', function() {
|
describe('Service definition helpers', function() {
|
||||||
test(findCategory, () => {
|
test(findCategory, () => {
|
||||||
given('build').expect({ id: 'build', name: 'Build' })
|
given('build').expect({ id: 'build', name: 'Build', keywords: ['build'] })
|
||||||
given('foo').expect(undefined)
|
given('foo').expect(undefined)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import definitions from '../../../service-definitions.yml'
|
|||||||
export interface Category {
|
export interface Category {
|
||||||
id: string
|
id: string
|
||||||
name: string
|
name: string
|
||||||
|
keywords: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ExampleSignature {
|
export interface ExampleSignature {
|
||||||
|
|||||||
@@ -1,21 +1,25 @@
|
|||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
module.exports = [
|
module.exports = [
|
||||||
{ id: 'build', name: 'Build' },
|
{ id: 'build', name: 'Build', keywords: ['build'] },
|
||||||
{ id: 'coverage', name: 'Code Coverage' },
|
{ id: 'coverage', name: 'Code Coverage', keywords: ['coverage'] },
|
||||||
{ id: 'analysis', name: 'Analysis' },
|
{ id: 'analysis', name: 'Analysis', keywords: ['analysis'] },
|
||||||
{ id: 'chat', name: 'Chat' },
|
{ id: 'chat', name: 'Chat', keywords: ['chat'] },
|
||||||
{ id: 'dependencies', name: 'Dependencies' },
|
{ id: 'dependencies', name: 'Dependencies', keywords: ['dependencies'] },
|
||||||
{ id: 'size', name: 'Size' },
|
{ id: 'size', name: 'Size', keywords: ['size'] },
|
||||||
{ id: 'downloads', name: 'Downloads' },
|
{ id: 'downloads', name: 'Downloads', keywords: ['downloads'] },
|
||||||
{ id: 'funding', name: 'Funding' },
|
{ id: 'funding', name: 'Funding', keywords: ['funding'] },
|
||||||
{ id: 'issue-tracking', name: 'Issue Tracking' },
|
{ id: 'issue-tracking', name: 'Issue Tracking', keywords: ['issue'] },
|
||||||
{ id: 'license', name: 'License' },
|
{ id: 'license', name: 'License', keywords: ['license'] },
|
||||||
{ id: 'rating', name: 'Rating' },
|
{ id: 'rating', name: 'Rating', keywords: ['rating'] },
|
||||||
{ id: 'social', name: 'Social' },
|
{ id: 'social', name: 'Social', keywords: ['social'] },
|
||||||
{ id: 'version', name: 'Version' },
|
{ id: 'version', name: 'Version', keywords: ['version'] },
|
||||||
{ id: 'platform-support', name: 'Platform & Version Support' },
|
{
|
||||||
{ id: 'monitoring', name: 'Monitoring' },
|
id: 'platform-support',
|
||||||
{ id: 'activity', name: 'Activity' },
|
name: 'Platform & Version Support',
|
||||||
{ id: 'other', name: 'Other' },
|
keywords: ['platform'],
|
||||||
|
},
|
||||||
|
{ id: 'monitoring', name: 'Monitoring', keywords: ['monitoring'] },
|
||||||
|
{ id: 'activity', name: 'Activity', keywords: ['activity'] },
|
||||||
|
{ id: 'other', name: 'Other', keywords: [] },
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -22,8 +22,6 @@ const releaseArraySchema = Joi.alternatives().try(
|
|||||||
Joi.array().length(0)
|
Joi.array().length(0)
|
||||||
)
|
)
|
||||||
|
|
||||||
const keywords = ['github download']
|
|
||||||
|
|
||||||
module.exports = class GithubDownloads extends GithubAuthV3Service {
|
module.exports = class GithubDownloads extends GithubAuthV3Service {
|
||||||
static get category() {
|
static get category() {
|
||||||
return 'downloads'
|
return 'downloads'
|
||||||
@@ -50,7 +48,6 @@ module.exports = class GithubDownloads extends GithubAuthV3Service {
|
|||||||
downloadCount: 857000,
|
downloadCount: 857000,
|
||||||
}),
|
}),
|
||||||
documentation,
|
documentation,
|
||||||
keywords,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'GitHub Releases',
|
title: 'GitHub Releases',
|
||||||
@@ -66,7 +63,6 @@ module.exports = class GithubDownloads extends GithubAuthV3Service {
|
|||||||
downloadCount: 27000,
|
downloadCount: 27000,
|
||||||
}),
|
}),
|
||||||
documentation,
|
documentation,
|
||||||
keywords,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'GitHub Pre-Releases',
|
title: 'GitHub Pre-Releases',
|
||||||
@@ -82,7 +78,6 @@ module.exports = class GithubDownloads extends GithubAuthV3Service {
|
|||||||
downloadCount: 2000,
|
downloadCount: 2000,
|
||||||
}),
|
}),
|
||||||
documentation,
|
documentation,
|
||||||
keywords,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'GitHub Releases (by Release)',
|
title: 'GitHub Releases (by Release)',
|
||||||
@@ -98,7 +93,6 @@ module.exports = class GithubDownloads extends GithubAuthV3Service {
|
|||||||
downloadCount: 490000,
|
downloadCount: 490000,
|
||||||
}),
|
}),
|
||||||
documentation,
|
documentation,
|
||||||
keywords,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'GitHub Releases (by Asset)',
|
title: 'GitHub Releases (by Asset)',
|
||||||
@@ -115,7 +109,6 @@ module.exports = class GithubDownloads extends GithubAuthV3Service {
|
|||||||
downloadCount: 3000,
|
downloadCount: 3000,
|
||||||
}),
|
}),
|
||||||
documentation,
|
documentation,
|
||||||
keywords,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'GitHub Pre-Releases (by Asset)',
|
title: 'GitHub Pre-Releases (by Asset)',
|
||||||
@@ -132,7 +125,6 @@ module.exports = class GithubDownloads extends GithubAuthV3Service {
|
|||||||
downloadCount: 237,
|
downloadCount: 237,
|
||||||
}),
|
}),
|
||||||
documentation,
|
documentation,
|
||||||
keywords,
|
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ const { age: ageColor } = require('../color-formatters')
|
|||||||
const { GithubAuthV3Service } = require('./github-auth-service')
|
const { GithubAuthV3Service } = require('./github-auth-service')
|
||||||
const { documentation, errorMessagesFor } = require('./github-helpers')
|
const { documentation, errorMessagesFor } = require('./github-helpers')
|
||||||
const commonExampleAttrs = {
|
const commonExampleAttrs = {
|
||||||
keywords: ['activity', 'latest'],
|
keywords: ['latest'],
|
||||||
documentation,
|
documentation,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ module.exports = class GithubLicense extends GithubAuthV3Service {
|
|||||||
message: 'MIT',
|
message: 'MIT',
|
||||||
color: 'green',
|
color: 'green',
|
||||||
},
|
},
|
||||||
keywords: ['license'],
|
|
||||||
documentation,
|
documentation,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -64,7 +64,6 @@ module.exports = class JiraSprint extends BaseJsonService {
|
|||||||
numTotalIssues: 28,
|
numTotalIssues: 28,
|
||||||
}),
|
}),
|
||||||
documentation,
|
documentation,
|
||||||
keywords: ['issues'],
|
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ module.exports = class VaadinDirectoryRatingCount extends BaseVaadinDirectorySer
|
|||||||
pattern: 'rating-count/:packageName',
|
pattern: 'rating-count/:packageName',
|
||||||
namedParams: { packageName: 'vaadinvaadin-grid' },
|
namedParams: { packageName: 'vaadinvaadin-grid' },
|
||||||
staticPreview: this.render({ ratingCount: 6 }),
|
staticPreview: this.render({ ratingCount: 6 }),
|
||||||
keywords: ['vaadin-directory', 'rating-count', 'rating count'],
|
keywords: ['vaadin-directory', 'rating-count'],
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ module.exports = class VaadinDirectoryRating extends BaseVaadinDirectoryService
|
|||||||
pattern: ':format(stars|rating)/:packageName',
|
pattern: ':format(stars|rating)/:packageName',
|
||||||
namedParams: { format: 'rating', packageName: 'vaadinvaadin-grid' },
|
namedParams: { format: 'rating', packageName: 'vaadinvaadin-grid' },
|
||||||
staticPreview: this.render({ format: 'rating', score: 4.75 }),
|
staticPreview: this.render({ format: 'rating', score: 4.75 }),
|
||||||
keywords: ['vaadin-directory', 'rating'],
|
keywords: ['vaadin-directory'],
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ module.exports = class VaadinDirectoryVersion extends BaseVaadinDirectoryService
|
|||||||
pattern: 'v/:packageName',
|
pattern: 'v/:packageName',
|
||||||
namedParams: { packageName: 'vaadinvaadin-grid' },
|
namedParams: { packageName: 'vaadinvaadin-grid' },
|
||||||
staticPreview: renderVersionBadge({ version: 'v5.3.0-alpha4' }),
|
staticPreview: renderVersionBadge({ version: 'v5.3.0-alpha4' }),
|
||||||
keywords: ['vaadin-directory', 'version', 'latest version'],
|
keywords: ['vaadin-directory', 'latest'],
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user