mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
lowercase and strip special chars from slugs
This commit is contained in:
parent
e054490a55
commit
458880baec
3 changed files with 6 additions and 2 deletions
|
|
@ -3,12 +3,14 @@ import React from 'react';
|
|||
import { RouteComponentProps } from 'react-router-dom';
|
||||
import slugify from 'slugify';
|
||||
|
||||
import { SlugifyOptions } from '../constants';
|
||||
|
||||
interface Props {
|
||||
listName: string;
|
||||
};
|
||||
|
||||
export const ListInfoButton = (props: RouteComponentProps & Props) => {
|
||||
const listPath = `/lists/${slugify(props.listName)}`;
|
||||
const listPath = `/lists/${slugify(props.listName, SlugifyOptions)}`;
|
||||
return (
|
||||
<Button
|
||||
type="primary"
|
||||
|
|
|
|||
1
src/FilterLists.Web/src/constants.ts
Normal file
1
src/FilterLists.Web/src/constants.ts
Normal file
|
|
@ -0,0 +1 @@
|
|||
export const SlugifyOptions = { remove: /[^a-zA-Z0-9- ]/g, lower: true }
|
||||
|
|
@ -1,11 +1,12 @@
|
|||
import slugify from 'slugify';
|
||||
|
||||
import { SlugifyOptions } from '../constants';
|
||||
import { List } from '../interfaces/List';
|
||||
import { useApiData } from './useApiData';
|
||||
|
||||
export const useLists = () => {
|
||||
const lists = useApiData<List[]>("/api/v1/lists");
|
||||
lists && lists.forEach(l => l.slug = slugify(l.name));
|
||||
lists && lists.forEach(l => l.slug = slugify(l.name, SlugifyOptions));
|
||||
return (lists || [])
|
||||
.sort((a: List, b: List) => a.name.localeCompare(b.name));
|
||||
};
|
||||
Loading…
Reference in a new issue