Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.

Commit 92bb811

Browse files
committed
Ready to be merged 🚀
1 parent 56e80a2 commit 92bb811

21 files changed

+76
-48
lines changed

.lighthouserc.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"uses-rel-preconnect": "off",
1313
"link-name": "off",
1414
"aria-valid-attr-value": "off",
15-
"unused-javascript": "off"
1615
}
1716
},
1817
"upload": {

__tests__/slug.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { generateTagSlug, generatePostSlug } from "../src/logic/slug";
2+
3+
describe("slug", () => {
4+
describe("tag", () => {
5+
it("generate slug for single word tag", () => {
6+
expect(generateTagSlug("macos")).toEqual("/blog/tags/macos/");
7+
});
8+
9+
it("generate slug for multiple word tag", () => {
10+
expect(generateTagSlug("mobile app")).toEqual("/blog/tags/mobile-app/");
11+
});
12+
});
13+
14+
it("post", () => {
15+
expect(generatePostSlug("/2017-05-10-about-me")).toEqual(
16+
"/2017/05/10/about-me"
17+
);
18+
});
19+
});

__tests__/url.test.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

gatsby-node.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
const path = require("path");
2+
const {
3+
slugs,
4+
generateTagSlug,
5+
generatePostSlug,
6+
} = require("./src/logic/slug");
27
const { createFilePath } = require("gatsby-source-filesystem");
38

49
exports.createPages = async ({ graphql, actions, reporter }) => {
@@ -28,7 +33,7 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
2833
);
2934

3035
if (result.errors) {
31-
reporter.panicOnBuild(`Error while running GraphQL query.`);
36+
reporter.panicOnBuild(`Create Pages Error while running GraphQL query.`);
3237
return;
3338
}
3439

@@ -50,7 +55,7 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
5055
const numberOfPages = Math.ceil(posts.length / postsPerPage);
5156
Array.from({ length: numberOfPages }).forEach((_, i) => {
5257
createPage({
53-
path: i === 0 ? `/blog/` : `/blog/${i + 1}`,
58+
path: i === 0 ? slugs.blog : `${slugs.blog}${i + 1}`,
5459
component: path.resolve("./src/templates/blog.tsx"),
5560
context: {
5661
limit: postsPerPage,
@@ -65,7 +70,7 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
6570
const tags = result.data.tagsGroup.group;
6671
tags.forEach((tag) => {
6772
createPage({
68-
path: `/blog/tags/${tag.fieldValue.split(" ").join("-")}/`,
73+
path: generateTagSlug(tag.fieldValue),
6974
component: path.resolve("./src/templates/tag.tsx"),
7075
context: {
7176
tag: tag.fieldValue,
@@ -78,8 +83,6 @@ exports.onCreateNode = ({ node, actions, getNode }) => {
7883
const { createNodeField } = actions;
7984
if (node.internal.type === `MarkdownRemark`) {
8085
const filename = createFilePath({ node, getNode, basePath: `pages` });
81-
const [year, month, day, ...title] = filename.substring(1).split("-");
82-
const slug = `/${year}/${month}/${day}/${title.join("-")}`;
83-
createNodeField({ node, name: `slug`, value: slug });
86+
createNodeField({ node, name: `slug`, value: generatePostSlug(filename) });
8487
}
8588
};

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@
2828
},
2929
"homepage": "https://github.com/chicio/chicio.github.io#readme",
3030
"scripts": {
31+
"start": "gatsby develop",
32+
"clean": "gatsby clean",
33+
"serve": "gatsby serve",
3134
"test": "jest",
3235
"test-ci": "./scripts/test-ci.sh",
33-
"start": "gatsby develop",
3436
"prebuild": "npm run test",
3537
"build": "gatsby build",
3638
"postbuild": "npm run build-storybook",
3739
"build-ci": "./scripts/build-ci.sh",
38-
"serve": "gatsby serve",
39-
"clean": "gatsby clean",
4040
"predeploy": "npm run clean && npm run build",
4141
"deploy": "gh-pages -d public -b main",
4242
"storybook": "start-storybook -p 6006",

src/components/design-system/molecules/post-tags.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Tag } from "./tag";
2-
import { generateTagUrl } from "../../../logic/url";
32
import React from "react";
43
import styled from "styled-components";
54
import { Maybe } from "../../../../graphql-types";
5+
import { generateTagSlug } from "../../../logic/slug";
66

77
export interface PostTagsProps {
88
tags: Maybe<string>[];
@@ -15,7 +15,7 @@ const PostTagsContainer = styled.div`
1515
export const PostTags: React.FC<PostTagsProps> = ({ tags }) => (
1616
<PostTagsContainer>
1717
{tags!.map((tag) => (
18-
<Tag tag={tag!} link={generateTagUrl(tag!)} big={false} key={tag} />
18+
<Tag tag={tag!} link={generateTagSlug(tag!)} big={false} key={tag} />
1919
))}
2020
</PostTagsContainer>
2121
);

src/components/design-system/organism/footer.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import styled from "styled-components";
55
import { MenuItem } from "../molecules/menu-item";
66
import { Paragraph } from "../atoms/paragraph";
77
import { StandardExternalLink } from "../atoms/standard-external-link";
8+
import { slugs } from "../../../logic/slug";
89

910
const FooterContainer = styled.footer`
1011
flex-shrink: 0;
@@ -83,7 +84,7 @@ export const Footer: React.FC<FooterProps> = ({ author, trackingCategory }) => (
8384
Home
8485
</FooterMenuItem>
8586
<FooterMenuItem
86-
to="/blog/"
87+
to={slugs.blog}
8788
onClick={() => {
8889
track(
8990
tracking.action.open_blog,
@@ -107,7 +108,7 @@ export const Footer: React.FC<FooterProps> = ({ author, trackingCategory }) => (
107108
About Me
108109
</FooterMenuItem>
109110
<FooterMenuItem
110-
to="/blog/archive/"
111+
to={slugs.archive}
111112
onClick={() => {
112113
track(
113114
tracking.action.open_blog_archive,
@@ -119,7 +120,7 @@ export const Footer: React.FC<FooterProps> = ({ author, trackingCategory }) => (
119120
Archive
120121
</FooterMenuItem>
121122
<FooterMenuItem
122-
to="/blog/tags/"
123+
to={slugs.tags}
123124
onClick={() => {
124125
track(
125126
tracking.action.open_blog_tags,

src/components/design-system/organism/menu.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { track, tracking } from "../../../logic/tracking";
33
import { MenuItem } from "../molecules/menu-item";
44
import styled, { css } from "styled-components";
55
import { Container } from "../atoms/container";
6+
import { slugs } from "../../../logic/slug";
67

78
const MenuContainer = styled.div`
89
background-color: ${(props) => props.theme.light.primaryColor};
@@ -77,8 +78,8 @@ export const Menu: React.FC<MenuProps> = ({ trackingCategory, pathname }) => (
7778
{"Home"}
7879
</NavBarMenuItem>
7980
<NavBarMenuItem
80-
selected={pathname !== "/2017/05/10/about-me/"}
81-
to={"/blog/"}
81+
selected={pathname !== slugs.aboutMe}
82+
to={slugs.blog}
8283
onClick={() => {
8384
track(
8485
tracking.action.open_blog,
@@ -90,8 +91,8 @@ export const Menu: React.FC<MenuProps> = ({ trackingCategory, pathname }) => (
9091
{"Blog"}
9192
</NavBarMenuItem>
9293
<NavBarMenuItem
93-
selected={pathname === "/2017/05/10/about-me/"}
94-
to={"/2017/05/10/about-me/"}
94+
selected={pathname === slugs.aboutMe}
95+
to={slugs.aboutMe}
9596
onClick={() => {
9697
track(
9798
tracking.action.open_about_me,

src/components/design-system/organism/profile-presentation.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { track, tracking } from "../../../logic/tracking";
66
import styled from "styled-components";
77
import { CallToActionInternal } from "../atoms/call-to-action-internal";
88
import { Heading2 } from "../atoms/heading2";
9+
import { slugs } from "../../../logic/slug";
910

1011
const Author = styled(Heading2)`
1112
color: ${(props) => props.theme.light.textAbovePrimaryColor};
@@ -94,7 +95,7 @@ export const ProfilePresentation: React.FC<ProfilePresentationProps> = ({
9495
tracking.label.body
9596
)
9697
}
97-
to="/blog/"
98+
to={slugs.blog}
9899
>
99100
Blog
100101
</BlogCallToAction>

src/components/head.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Helmet } from "react-helmet";
33
import { graphql, useStaticQuery } from "gatsby";
44
import { HeadQuery } from "../../graphql-types";
55
import { createJsonLD, createMetaAttributes, OgPageType } from "../logic/seo";
6+
import { primaryColorDark } from "./theme";
67

78
const cookieConsetCss = `
89
.cc-window{opacity:1;transition:opacity 1s ease}.cc-window.cc-invisible{opacity:0}.cc-animate.cc-revoke{transition:transform 1s ease}.cc-animate.cc-revoke.cc-top{transform:translateY(-2em)}.cc-animate.cc-revoke.cc-bottom{transform:translateY(2em)}.cc-animate.cc-revoke.cc-active.cc-bottom,.cc-animate.cc-revoke.cc-active.cc-top,.cc-revoke:hover{transform:translateY(0)}.cc-grower{max-height:0;overflow:hidden;transition:max-height 1s}
@@ -19,7 +20,7 @@ if (typeof window !== "undefined") {
1920
window.cookieconsent.initialise({
2021
palette: {
2122
popup: {
22-
background: '#303F9F',
23+
background: '${primaryColorDark}',
2324
text: '#ffffff'
2425
},
2526
button: {

0 commit comments

Comments
 (0)