-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
refactor: replace route's format with pattern in [StaticBadge] & modified [website]
#11865
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
374ed56
717825c
1346091
5c165d7
4abfd7d
7f916a9
fa11e0e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /** | ||
| * Helpers for parsing badge content from a dash seperated single parameter. | ||
| * | ||
| * @module | ||
| */ | ||
|
|
||
| /** | ||
| * Split string on dashses, but escape dash if double. | ||
| * Escape slash if double. | ||
| * | ||
| * @param {string} s - String to split. | ||
| * @returns {string[]} Parts of the string, split on unescaped dashes. | ||
| */ | ||
| function splitDashSeparatedOptionalParams(s) { | ||
| const parts = [] | ||
| let cur = '' | ||
| for (let i = 0; i < s.length; ) { | ||
| const ch = s[i] | ||
| const next = s[i + 1] | ||
| if (ch === '-' && next === '-') { | ||
| cur += '-' | ||
| i += 2 | ||
| } else if (ch === '/' && next === '/') { | ||
| cur += '/' | ||
| i += 2 | ||
| } else if (ch === '-') { | ||
| parts.push(cur) | ||
| cur = '' | ||
| i += 1 | ||
| } else { | ||
| cur += ch | ||
| i += 1 | ||
| } | ||
| } | ||
| parts.push(cur) | ||
| return parts | ||
| } | ||
|
|
||
| export { splitDashSeparatedOptionalParams } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { test, given } from 'sazerac' | ||
| import { splitDashSeparatedOptionalParams } from './dash-badge-content-helpers.js' | ||
|
|
||
| describe('Dash badge content helpers', function () { | ||
| test(splitDashSeparatedOptionalParams, () => { | ||
| given('foo-bar-baz').expect(['foo', 'bar', 'baz']) | ||
| given('foo--bar-baz').expect(['foo-bar', 'baz']) | ||
| given('foo-bar--baz').expect(['foo', 'bar-baz']) | ||
| given('foo--bar--baz').expect(['foo-bar-baz']) | ||
| given('foo//bar-baz').expect(['foo/bar', 'baz']) | ||
| given('foo//bar//baz').expect(['foo/bar/baz']) | ||
| }) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { redirector } from '../index.js' | ||
|
|
||
| export default redirector({ | ||
| category: 'static', | ||
| name: 'StaticBadgeColonRedirect', | ||
| route: { | ||
| base: '', | ||
| pattern: '\\::badgeContent', | ||
| }, | ||
| transformPath: ({ badgeContent }) => `/badge/${badgeContent}`, | ||
| dateAdded: new Date('2026-05-21'), | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { createServiceTester } from '../tester.js' | ||
| export const t = await createServiceTester() | ||
|
|
||
| t.create('static badge colon redirect: basic redirect') | ||
| .get('/:label-message-blue') | ||
| .expectRedirect('/badge/label-message-blue.svg') | ||
|
|
||
| t.create('static badge colon redirect: with spaces and dash encoding') | ||
| .get('/:all%20one%20color-red') | ||
| .expectRedirect('/badge/all%20one%20color-red.svg') | ||
|
|
||
| t.create('static badge colon redirect: double dash and underscore encoding') | ||
| .get('/:best--license-Apache--2.0-blue') | ||
| .expectRedirect('/badge/best--license-Apache--2.0-blue.svg') | ||
|
|
||
| t.create('static badge colon redirect: missing label') | ||
| .get('/:-message-blue') | ||
| .expectRedirect('/badge/-message-blue.svg') | ||
|
|
||
| t.create('static badge colon redirect: missing message') | ||
| .get('/:label--blue') | ||
| .expectRedirect('/badge/label--blue.svg') |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,7 +31,7 @@ t.create('Not a valid color') | |
| }) | ||
|
|
||
| t.create('Missing message') | ||
| .get('/badge/label--blue.json') | ||
| .get('/badge/label-%20-blue.json') | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is hardly in use, users get the exact same result using a space |
||
| .expectBadge({ label: 'label', message: '', color: 'blue' }) | ||
|
|
||
| t.create('Missing label') | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import { escapeFormat } from '../../core/badge-urls/path-helpers.js' | ||
| import { redirector } from '../index.js' | ||
| import { splitDashSeparatedOptionalParams } from '../dash-badge-content-helpers.js' | ||
|
|
||
| function escapeFormatSlashes(t) { | ||
| return ( | ||
|
|
@@ -9,31 +10,6 @@ function escapeFormatSlashes(t) { | |
| ) | ||
| } | ||
|
|
||
| function splitDashSeparatedOptionalParams(s) { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is now a helper function shared with |
||
| const parts = [] | ||
| let cur = '' | ||
| for (let i = 0; i < s.length; ) { | ||
| const ch = s[i] | ||
| const next = s[i + 1] | ||
| if (ch === '-' && next === '-') { | ||
| cur += '-' | ||
| i += 2 | ||
| } else if (ch === '/' && next === '/') { | ||
| cur += '/' | ||
| i += 2 | ||
| } else if (ch === '-') { | ||
| parts.push(cur) | ||
| cur = '' | ||
| i += 1 | ||
| } else { | ||
| cur += ch | ||
| i += 1 | ||
| } | ||
| } | ||
| parts.push(cur) | ||
| return parts | ||
| } | ||
|
|
||
| /* | ||
| Old documentation, for reference: | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is undocumented, so i think its better as a redirect with its own path rather then adding logic to usage of
badgeContentof the service