Skip to content

Commit fa7eee6

Browse files
committed
Merge branch 'add-typescript' of https://github.com/khendrikse/khendrikse.github.io into add-typescript
2 parents a6d6bc3 + 5474b09 commit fa7eee6

9 files changed

+86
-13
lines changed

helpers/generate-article-structured-data.js helpers/generate-article-structured-data.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
1-
const generateArticleStructuredData = ({ title, slug, description, image, date }) => {
1+
type StructuredDataInput = {
2+
title: string;
3+
slug: string;
4+
description: string;
5+
image: string;
6+
date: string;
7+
};
8+
9+
const generateArticleStructuredData = ({
10+
title,
11+
slug,
12+
description,
13+
image,
14+
date
15+
}: StructuredDataInput) => {
216
const BASE_URL = 'https://khendrikse.github.io/';
317

418
const json = {

helpers/parse-posts.js helpers/parse-posts.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import matter from 'gray-matter';
22

3-
const parsePosts = context => {
3+
const parsePosts = (context: __WebpackModuleApi.RequireContext) => {
44
const keys = context.keys();
5-
const values = keys.map(context);
5+
const values = keys.map(key => context(key));
66

77
const data = keys
88
.map((key, index) => {
@@ -12,11 +12,15 @@ const parsePosts = context => {
1212

1313
return {
1414
...document.data,
15+
oldBlog: document.data.oldBlog,
16+
tags: document.data.tags,
17+
date: document.data.date,
18+
published: document.data.published,
1519
markdownBody: document.content,
1620
slug
1721
};
1822
})
19-
.sort((a, b) => new Date(b.date) - new Date(a.date))
23+
.sort((a, b) => new Date(b.date).valueOf() - new Date(a.date).valueOf())
2024
.filter(post => post.published);
2125
return data;
2226
};

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@
3636
"showdown": "^1.9.1"
3737
},
3838
"devDependencies": {
39+
"@types/jest": "^27.4.0",
3940
"@types/react": "^17.0.39",
41+
"@types/react-syntax-highlighter": "^13.5.2",
42+
"@types/react-test-renderer": "^17.0.1",
4043
"@types/webpack-env": "^1.16.3",
4144
"eslint": "^8.6.0",
4245
"eslint-config-airbnb": "^19.0.4",

pages/blog/[postname].tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import isExternalImage from 'helpers/is-external-image';
1414
import generateArticleStructuredData from 'helpers/generate-article-structured-data';
1515
import generateFaqStructuredData from 'helpers/generate-faq-structured-data';
1616
import parsePosts from 'helpers/parse-posts';
17-
import { Post, StaticPropsContextParams, BlogPostProps } from 'interfaces';
17+
import { StaticPropsContextParams, BlogPostProps } from 'interfaces';
1818

1919
export const BlogPost = ({
2020
siteTitle,
@@ -135,7 +135,7 @@ export const getStaticProps: GetStaticProps = async context => {
135135
export async function getStaticPaths() {
136136
const allPosts = parsePosts(
137137
require.context('../../posts', true, /\.\/.*\.md$/)
138-
).map((post: Post) => post.slug);
138+
).map((post) => post.slug);
139139

140140
const paths = allPosts.map((slug: string) => `/blog/${slug}`);
141141

pages/blog/category/[categoryname].tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import matter from 'gray-matter';
33
import BlogPage from 'components/BlogPage';
44
import parsePosts from 'helpers/parse-posts';
55
import getCategories from 'helpers/get-categories';
6-
import { Post, StaticPropsContextParams, BlogProps } from 'interfaces';
6+
import { StaticPropsContextParams, BlogProps } from 'interfaces';
77

88
const socialMeta = {
99
image:
@@ -35,7 +35,7 @@ export const getStaticProps: GetStaticProps = async context => {
3535
);
3636

3737
const categories = getCategories(allPosts);
38-
const posts = allPosts.filter((post: Post) =>
38+
const posts = allPosts.filter(post =>
3939
post?.tags?.includes(`${categoryname}`)
4040
);
4141

pages/post/[postname].tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import isExternalImage from 'helpers/is-external-image';
1414
import generateArticleStructuredData from 'helpers/generate-article-structured-data';
1515
import generateFaqStructuredData from 'helpers/generate-faq-structured-data';
1616
import parsePosts from '../../helpers/parse-posts';
17-
import { Post, StaticPropsContextParams, BlogPostProps } from 'interfaces';
17+
import { StaticPropsContextParams, BlogPostProps } from 'interfaces';
1818

1919
export default function BlogPost({
2020
siteTitle,
@@ -140,8 +140,8 @@ export async function getStaticPaths() {
140140
const allPosts = parsePosts(
141141
require.context('../../posts', true, /\.\/.*\.md$/)
142142
)
143-
.filter((post: Post) => post.oldBlog)
144-
.map((post: Post) => post.date.concat('-', post.slug));
143+
.filter(post => post.oldBlog)
144+
.map(post => post.date.concat('-', post.slug));
145145

146146
const paths = allPosts.map((slug: string) => `/post/${slug}`);
147147

tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"allowJs": true,
77
"types": [
88
"node",
9-
"webpack-env" // here
9+
"webpack-env",
10+
"jest"
1011
],
1112
"skipLibCheck": true,
1213
"strict": true,

yarn.lock

+52-1
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,14 @@
964964
dependencies:
965965
"@types/istanbul-lib-report" "*"
966966

967+
"@types/jest@^27.4.0":
968+
version "27.4.0"
969+
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-27.4.0.tgz#037ab8b872067cae842a320841693080f9cb84ed"
970+
integrity sha512-gHl8XuC1RZ8H2j5sHv/JqsaxXkDDM9iDOgu0Wp8sjs4u/snb2PVehyWXJPr+ORA0RPpgw231mnutWI1+0hgjIQ==
971+
dependencies:
972+
jest-diff "^27.0.0"
973+
pretty-format "^27.0.0"
974+
967975
"@types/json-schema@^7.0.5", "@types/json-schema@^7.0.6":
968976
version "7.0.7"
969977
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.7.tgz#98a993516c859eb0d5c4c8f098317a9ea68db9ad"
@@ -1021,7 +1029,21 @@
10211029
resolved "https://registry.yarnpkg.com/@types/q/-/q-1.5.4.tgz#15925414e0ad2cd765bfef58842f7e26a7accb24"
10221030
integrity sha512-1HcDas8SEj4z1Wc696tH56G8OlRaH/sqZOynNNB+HF0WOeXPaxTtbYzJY2oEfiUxjSKjhCKr+MvR7dCHcEelug==
10231031

1024-
"@types/react@^17.0.39":
1032+
"@types/react-syntax-highlighter@^13.5.2":
1033+
version "13.5.2"
1034+
resolved "https://registry.yarnpkg.com/@types/react-syntax-highlighter/-/react-syntax-highlighter-13.5.2.tgz#357cc03581dc434c57c3b31f70e0eecdbf7b3ab0"
1035+
integrity sha512-sRZoKZBGKaE7CzMvTTgz+0x/aVR58ZYUTfB7HN76vC+yQnvo1FWtzNARBt0fGqcLGEVakEzMu/CtPzssmanu8Q==
1036+
dependencies:
1037+
"@types/react" "*"
1038+
1039+
"@types/react-test-renderer@^17.0.1":
1040+
version "17.0.1"
1041+
resolved "https://registry.yarnpkg.com/@types/react-test-renderer/-/react-test-renderer-17.0.1.tgz#3120f7d1c157fba9df0118dae20cb0297ee0e06b"
1042+
integrity sha512-3Fi2O6Zzq/f3QR9dRnlnHso9bMl7weKCviFmfF6B4LS1Uat6Hkm15k0ZAQuDz+UBq6B3+g+NM6IT2nr5QgPzCw==
1043+
dependencies:
1044+
"@types/react" "*"
1045+
1046+
"@types/react@*", "@types/react@^17.0.39":
10251047
version "17.0.39"
10261048
resolved "https://registry.yarnpkg.com/@types/react/-/react-17.0.39.tgz#d0f4cde092502a6db00a1cded6e6bf2abb7633ce"
10271049
integrity sha512-UVavlfAxDd/AgAacMa60Azl7ygyQNRwC/DsHZmKgNvPmRR5p70AJ5Q9EAmL2NWOJmeV+vVUI4IAP7GZrN8h8Ug==
@@ -2629,6 +2651,11 @@ diff-sequences@^27.5.0:
26292651
resolved "https://registry.yarnpkg.com/diff-sequences/-/diff-sequences-27.5.0.tgz#a8ac0cb742b17d6f30a6c43e233893a2402c0729"
26302652
integrity sha512-ZsOBWnhXiH+Zn0DcBNX/tiQsqrREHs/6oQsEVy2VJJjrTblykPima11pyHMSA/7PGmD+fwclTnKVKL/qtNREDQ==
26312653

2654+
diff-sequences@^27.5.1:
2655+
version "27.5.1"
2656+
resolved "https://registry.yarnpkg.com/diff-sequences/-/diff-sequences-27.5.1.tgz#eaecc0d327fd68c8d9672a1e64ab8dccb2ef5327"
2657+
integrity sha512-k1gCAXAsNgLwEL+Y8Wvl+M6oEFj5bgazfZULpS5CneoPPXRaCCW7dm+q21Ky2VEE5X+VeRDBVg1Pcvvsr4TtNQ==
2658+
26322659
diff@^5.0.0:
26332660
version "5.0.0"
26342661
resolved "https://registry.yarnpkg.com/diff/-/diff-5.0.0.tgz#7ed6ad76d859d030787ec35855f5b1daf31d852b"
@@ -4671,6 +4698,16 @@ jest-config@^27.5.0:
46714698
pretty-format "^27.5.0"
46724699
slash "^3.0.0"
46734700

4701+
jest-diff@^27.0.0:
4702+
version "27.5.1"
4703+
resolved "https://registry.yarnpkg.com/jest-diff/-/jest-diff-27.5.1.tgz#a07f5011ac9e6643cf8a95a462b7b1ecf6680def"
4704+
integrity sha512-m0NvkX55LDt9T4mctTEgnZk3fmEg3NRYutvMPWM/0iPnkFj2wIeF45O1718cMSOFO1vINkqmxqD8vE37uTEbqw==
4705+
dependencies:
4706+
chalk "^4.0.0"
4707+
diff-sequences "^27.5.1"
4708+
jest-get-type "^27.5.1"
4709+
pretty-format "^27.5.1"
4710+
46744711
jest-diff@^27.5.0:
46754712
version "27.5.0"
46764713
resolved "https://registry.yarnpkg.com/jest-diff/-/jest-diff-27.5.0.tgz#34dc608a3b9159df178dd480b6d835b5e6b92082"
@@ -4729,6 +4766,11 @@ jest-get-type@^27.5.0:
47294766
resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-27.5.0.tgz#861c24aa1b176be83c902292cb9618d580cac8a7"
47304767
integrity sha512-Vp6O8a52M/dahXRG/E0EJuWQROps2mDQ0sJYPgO8HskhdLwj9ajgngy2OAqZgV6e/RcU67WUHq6TgfvJb8flbA==
47314768

4769+
jest-get-type@^27.5.1:
4770+
version "27.5.1"
4771+
resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-27.5.1.tgz#3cd613c507b0f7ace013df407a1c1cd578bcb4f1"
4772+
integrity sha512-2KY95ksYSaK7DMBWQn6dQz3kqAf3BB64y2udeG+hv4KfSOb9qwcYQstTJc1KCbsix+wLZWZYN8t7nwX3GOBLRw==
4773+
47324774
jest-haste-map@^27.5.0:
47334775
version "27.5.0"
47344776
resolved "https://registry.yarnpkg.com/jest-haste-map/-/jest-haste-map-27.5.0.tgz#7cc3a920caf304c89fbfceb5d5717b929873f175"
@@ -6760,6 +6802,15 @@ prettier@^2.3.2:
67606802
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.5.1.tgz#fff75fa9d519c54cf0fce328c1017d94546bc56a"
67616803
integrity sha512-vBZcPRUR5MZJwoyi3ZoyQlc1rXeEck8KgeC9AwwOn+exuxLxq5toTRDTSaVrXHxelDMHy9zlicw8u66yxoSUFg==
67626804

6805+
pretty-format@^27.0.0, pretty-format@^27.5.1:
6806+
version "27.5.1"
6807+
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-27.5.1.tgz#2181879fdea51a7a5851fb39d920faa63f01d88e"
6808+
integrity sha512-Qb1gy5OrP5+zDf2Bvnzdl3jsTf1qXVMazbvCoKhtKqVs4/YK4ozX4gKQJJVyNe+cajNPn0KoC0MC3FUmaHWEmQ==
6809+
dependencies:
6810+
ansi-regex "^5.0.1"
6811+
ansi-styles "^5.0.0"
6812+
react-is "^17.0.1"
6813+
67636814
pretty-format@^27.5.0:
67646815
version "27.5.0"
67656816
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-27.5.0.tgz#71e1af7a4b587d259fa4668dcd3e94af077767cb"

0 commit comments

Comments
 (0)