mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-03-28 17:42:40 +01:00
#842 - Allow the slug to be set to an empty value
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
|
||||
### 🐞 Fixes
|
||||
|
||||
- [#842](https://github.com/estruyf/vscode-front-matter/issues/842): Allow to set the `frontMatter.taxonomy.slugTemplate` setting to an empty string
|
||||
- [#845](https://github.com/estruyf/vscode-front-matter/issues/845): Fix empty values for number fields
|
||||
|
||||
## [10.3.0] - 2024-08-13 - [Release notes](https://beta.frontmatter.codes/updates/v10.3.0)
|
||||
|
||||
@@ -1993,7 +1993,8 @@
|
||||
"scope": "Taxonomy"
|
||||
},
|
||||
"frontMatter.taxonomy.slugTemplate": {
|
||||
"type": "string",
|
||||
"type": ["string", "null"],
|
||||
"default": null,
|
||||
"markdownDescription": "%setting.frontMatter.taxonomy.slugTemplate.markdownDescription%",
|
||||
"scope": "Taxonomy"
|
||||
},
|
||||
|
||||
@@ -175,7 +175,7 @@ export class Article {
|
||||
if (article?.data) {
|
||||
const slug = SlugHelper.createSlug(title, article?.data, slugTemplate);
|
||||
|
||||
if (slug) {
|
||||
if (typeof slug === 'string') {
|
||||
return {
|
||||
slug,
|
||||
slugWithPrefixAndSuffix: `${prefix}${slug}${suffix}`
|
||||
@@ -214,7 +214,11 @@ export class Article {
|
||||
const articleTitle: string = article.data[titleField];
|
||||
const slugInfo = Article.generateSlug(articleTitle, article, contentType.slugTemplate);
|
||||
|
||||
if (slugInfo && slugInfo.slug && slugInfo.slugWithPrefixAndSuffix) {
|
||||
if (
|
||||
slugInfo &&
|
||||
typeof slugInfo.slug === 'string' &&
|
||||
typeof slugInfo.slugWithPrefixAndSuffix === 'string'
|
||||
) {
|
||||
article.data['slug'] = slugInfo.slugWithPrefixAndSuffix;
|
||||
|
||||
if (contentType) {
|
||||
|
||||
@@ -17,11 +17,11 @@ export class SlugHelper {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!slugTemplate) {
|
||||
slugTemplate = Settings.get<string>(SETTING_SLUG_TEMPLATE) || undefined;
|
||||
if (slugTemplate === undefined || slugTemplate === null) {
|
||||
slugTemplate = Settings.get<string>(SETTING_SLUG_TEMPLATE);
|
||||
}
|
||||
|
||||
if (slugTemplate) {
|
||||
if (typeof slugTemplate === 'string') {
|
||||
if (slugTemplate.includes('{{title}}')) {
|
||||
const regex = new RegExp('{{title}}', 'g');
|
||||
slugTemplate = slugTemplate.replace(regex, articleTitle.toLowerCase().replace(/\s/g, '-'));
|
||||
|
||||
@@ -46,7 +46,7 @@ export const SlugField: React.FunctionComponent<ISlugFieldProps> = ({
|
||||
if (text !== value) {
|
||||
setText(value);
|
||||
}
|
||||
}, [value]);
|
||||
}, [text, value]);
|
||||
|
||||
useEffect(() => {
|
||||
if (titleValue) {
|
||||
@@ -54,7 +54,7 @@ export const SlugField: React.FunctionComponent<ISlugFieldProps> = ({
|
||||
title: titleValue,
|
||||
slugTemplate
|
||||
}).then((slug) => {
|
||||
if (slug.slugWithPrefixAndSuffix) {
|
||||
if (typeof slug.slugWithPrefixAndSuffix === "string") {
|
||||
setSlug(slug.slugWithPrefixAndSuffix);
|
||||
}
|
||||
}).catch((_) => {
|
||||
|
||||
@@ -131,6 +131,8 @@ export const WrapperField: React.FunctionComponent<IWrapperFieldProps> = ({
|
||||
if (fieldValue === undefined || value !== fieldValue) {
|
||||
if (typeof value === 'number') {
|
||||
setFieldValue(value);
|
||||
} else if (field.type === "slug") {
|
||||
setFieldValue(value);
|
||||
} else {
|
||||
setFieldValue(value || null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user