Unify slugify()
Provides a new util.js file with a unified `slugify()` function that also lowercases the slug. Change all uses of `slugify()` to use this instead.
This commit is contained in:
parent
b9fe8c7f38
commit
6109bb690d
5 changed files with 15 additions and 6 deletions
|
|
@ -3,9 +3,9 @@ import React, { Component } from 'react';
|
||||||
import Icon from 'react-fontawesome';
|
import Icon from 'react-fontawesome';
|
||||||
import Markdown from 'react-markdown';
|
import Markdown from 'react-markdown';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import slugify from 'slugify';
|
|
||||||
|
|
||||||
import { ListLink } from './Nav';
|
import { ListLink } from './Nav';
|
||||||
|
import { slugify } from './util';
|
||||||
|
|
||||||
|
|
||||||
class Article extends Component {
|
class Article extends Component {
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import slugify from 'slugify';
|
|
||||||
|
|
||||||
import Icon from 'react-fontawesome';
|
import Icon from 'react-fontawesome';
|
||||||
|
|
||||||
import { Row } from './skeleton';
|
import { Row } from './skeleton';
|
||||||
|
import { slugify } from './util';
|
||||||
|
|
||||||
|
|
||||||
class ListLink extends Component {
|
class ListLink extends Component {
|
||||||
|
|
@ -36,7 +36,7 @@ class NavList extends Component {
|
||||||
for (let page of blob.pages) {
|
for (let page of blob.pages) {
|
||||||
let slug = page.slug;
|
let slug = page.slug;
|
||||||
if (!slug) {
|
if (!slug) {
|
||||||
slug = slugify(page.title).toLowerCase();
|
slug = slugify(page.title);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (page.parent == null) {
|
if (page.parent == null) {
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
import hljs from 'highlight.js';
|
import hljs from 'highlight.js';
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import Markdown from 'react-markdown';
|
import Markdown from 'react-markdown';
|
||||||
import slugify from 'slugify';
|
|
||||||
|
|
||||||
import { NotFound } from './NotFound';
|
import { NotFound } from './NotFound';
|
||||||
|
import { slugify } from './util';
|
||||||
|
|
||||||
|
|
||||||
class Page extends Component {
|
class Page extends Component {
|
||||||
|
|
@ -25,7 +25,7 @@ class Page extends Component {
|
||||||
for (let page of blob.pages) {
|
for (let page of blob.pages) {
|
||||||
let slug = page.slug;
|
let slug = page.slug;
|
||||||
if (!slug) {
|
if (!slug) {
|
||||||
slug = slugify(page.title).toLowerCase();
|
slug = slugify(page.title);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (slug === this.params.slug) {
|
if (slug === this.params.slug) {
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import slugify from 'slugify';
|
|
||||||
|
|
||||||
import { Article } from './Article';
|
import { Article } from './Article';
|
||||||
import { HistoryNav } from './Nav';
|
import { HistoryNav } from './Nav';
|
||||||
import { NotFound } from './NotFound';
|
import { NotFound } from './NotFound';
|
||||||
|
import { slugify } from './util';
|
||||||
|
|
||||||
|
|
||||||
class Post extends Component {
|
class Post extends Component {
|
||||||
|
|
|
||||||
9
src/util.js
Normal file
9
src/util.js
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
import baseSlugify from 'slugify';
|
||||||
|
|
||||||
|
|
||||||
|
function slugify(s) {
|
||||||
|
// Slugify a string to our specs. Hooray consistency!
|
||||||
|
return baseSlugify(s).toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
export { slugify };
|
||||||
Loading…
Add table
Add a link
Reference in a new issue