Skip to content

Commit b94d4fd

Browse files
support special tags such as c++, c#
1 parent f173452 commit b94d4fd

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

lib/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function urlNoProtocal(url) {
4343
}
4444

4545
function urlAlias(url) {
46-
const regex = /https?:\/\/|www\.|\?.+|#.+|\/$/g;
46+
const regex = /https?:\/\/|www\.|\?.+|#.+|index\.html|\/$/g;
4747
url = url.replace(regex, '');
4848
// Replace one more time
4949
url = url.replace(regex, '');
@@ -92,7 +92,8 @@ function validateCategory(tag) {
9292
}
9393

9494
function validateTag(tag) {
95-
return /^[a-z0-9][a-z0-9-]*[a-z0-9]$/.test(tag);
95+
const validTags = ['c++', 'c/c++', 'c#', '.net'];
96+
return /^[a-z0-9][a-z0-9-]*[a-z0-9]$/.test(tag) || validTags.includes(tag);
9697
}
9798

9899
function stringify(doc, key) {
@@ -117,6 +118,7 @@ function validate(doc, options) {
117118
}
118119

119120
try {
121+
doc.url = doc.url.replace(/index\.html/g, '');
120122
doc.url = new URL(doc.url).href;
121123
} catch (_) {
122124
throw new TypeError('invalid url.' + stringify(doc, 'url'));

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dev-blog-directory-save",
3-
"version": "0.4.3",
3+
"version": "0.4.4",
44
"description": "API for save new blogs to dev-blog-directory.",
55
"main": "lib/index.js",
66
"scripts": {

test/main.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,9 @@ describe('dev-blog-directory-save', () => {
454454
'foo-foo',
455455
'FOO-Bar',
456456
'foo,bar',
457-
['foo-bar', 'A-TAG']
457+
['foo-bar', 'A-TAG'],
458+
'c++',
459+
['c++', 'c/c++', 'c#', '.net']
458460
];
459461

460462
validTags.forEach((tags, i) => {

0 commit comments

Comments
 (0)