Skip to content

Commit b54e008

Browse files
committed
use a slug for urls
1 parent 4fec19a commit b54e008

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export const routes = [
167167
component: PostsRoot,
168168
},
169169
{
170-
path: '/post/:issueNumber',
170+
path: '/post/:issueNumber/:slug?',
171171
exact: true,
172172
strict: false,
173173
query: postRootQuery,

src/Post.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,17 +344,24 @@ export const ReactionBar = ({
344344
);
345345
};
346346

347+
function slugify(s: string): string {
348+
return lowerCase(s).replace(/[^A-Za-z0-9-]+/g, '-');
349+
}
350+
347351
export function postUrl({
348352
post,
349353
viewComments,
350354
}: {
351355
post: {
352356
+number: number,
353357
+repository: {+owner: {+login: string}, +name: string},
358+
+title: string,
354359
},
355360
viewComments?: boolean,
356361
}) {
357-
return `/post/${post.number}${viewComments ? '#comments' : ''}`;
362+
return `/post/${post.number}/${slugify(post.title)}${
363+
viewComments ? '#comments' : ''
364+
}`;
358365
}
359366

360367
const Post = ({relay, post}: Props) => {

0 commit comments

Comments
 (0)