Skip to content
Permalink
Browse files

dynamic routing test

  • Loading branch information
7ma7X committed Aug 26, 2019
1 parent fddd0d2 commit d8a73174a39805c86a67738cda6dfadae0439740
Showing with 7 additions and 1 deletion.
  1. +7 −1 components/posts-renderer.tsx
@@ -5,12 +5,18 @@ import { useState } from "react";
const postsDateList = data["postsDateList"];
const postsComponentList: JSX.Element[] = [];

const internalLink = (date: String) => {
return date.replace(/^(\d{4})-(\d{2})-(\d{2})$/, (match, p1, p2, p3) => {
return `/posts/${p1}${p2}${p3}`;
})
}

for (const date of postsDateList) {
const { meta } = require(`../pages/posts/${date}`);
postsComponentList.push(
<div className="blog" key={meta.date}>
<div className="date">{meta.date}</div>
<div className="title"><Link prefetch={false} scroll={false} href={meta.url}><a>{meta.title}</a></Link></div>
<div className="title"><Link scroll={false} href={internalLink(meta.date)} as={meta.url}><a>{meta.title}</a></Link></div>
</div>
);
}

0 comments on commit d8a7317

Please sign in to comment.
You can’t perform that action at this time.