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

Commit fb9bdc6

Browse files
authored
Merge pull request #66 from chicio/duplication-centralize-data 🚀
Remove duplication and centralize data #60
2 parents ec56116 + b69fcf0 commit fb9bdc6

27 files changed

+163
-138
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77

88
jobs:
99
build:
10-
name: Build
10+
name: Test
1111
runs-on: macos-latest
1212
steps:
1313
- name: Checkout

.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
};

graphql-types.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,6 @@ export type DirectoryCtimeArgs = {
258258
export type Site = Node & {
259259
buildTime?: Maybe<Scalars['Date']>;
260260
siteMetadata?: Maybe<SiteSiteMetadata>;
261-
port?: Maybe<Scalars['Int']>;
262-
host?: Maybe<Scalars['String']>;
263261
polyfill?: Maybe<Scalars['Boolean']>;
264262
pathPrefix?: Maybe<Scalars['String']>;
265263
id: Scalars['ID'];
@@ -1011,8 +1009,6 @@ export type QueryAllDirectoryArgs = {
10111009
export type QuerySiteArgs = {
10121010
buildTime?: Maybe<DateQueryOperatorInput>;
10131011
siteMetadata?: Maybe<SiteSiteMetadataFilterInput>;
1014-
port?: Maybe<IntQueryOperatorInput>;
1015-
host?: Maybe<StringQueryOperatorInput>;
10161012
polyfill?: Maybe<BooleanQueryOperatorInput>;
10171013
pathPrefix?: Maybe<StringQueryOperatorInput>;
10181014
id?: Maybe<StringQueryOperatorInput>;
@@ -2187,8 +2183,6 @@ export type SiteFieldsEnum =
21872183
| 'siteMetadata___contacts___links___medium'
21882184
| 'siteMetadata___contacts___links___devto'
21892185
| 'siteMetadata___contacts___links___instagram'
2190-
| 'port'
2191-
| 'host'
21922186
| 'polyfill'
21932187
| 'pathPrefix'
21942188
| 'id'
@@ -2290,8 +2284,6 @@ export type SiteGroupConnection = {
22902284
export type SiteFilterInput = {
22912285
buildTime?: Maybe<DateQueryOperatorInput>;
22922286
siteMetadata?: Maybe<SiteSiteMetadataFilterInput>;
2293-
port?: Maybe<IntQueryOperatorInput>;
2294-
host?: Maybe<StringQueryOperatorInput>;
22952287
polyfill?: Maybe<BooleanQueryOperatorInput>;
22962288
pathPrefix?: Maybe<StringQueryOperatorInput>;
22972289
id?: Maybe<StringQueryOperatorInput>;

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",
Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
11
import React from "react";
22
import Particles from "react-tsparticles";
3-
import { useIsPowerfulMobileDevice } from "../logic/device";
4-
import { isDesktop } from "react-device-detect";
53
import { useParticlesConfiguration } from "../logic/particles";
64

75
export const BackgroundFullScreen: React.FC = () => {
8-
const isPowerfulMobileDevice = useIsPowerfulMobileDevice();
96
const particlesConfiguration = useParticlesConfiguration();
107

118
return (
12-
<div>
13-
{(isDesktop || isPowerfulMobileDevice) && (
14-
<Particles
15-
id="tsparticles"
16-
style={{
17-
position: "absolute",
18-
top: 0,
19-
left: 0,
20-
}}
21-
options={particlesConfiguration}
22-
/>
23-
)}
24-
</div>
9+
<Particles
10+
id="tsparticles"
11+
style={{
12+
position: "absolute",
13+
top: 0,
14+
left: 0,
15+
}}
16+
options={particlesConfiguration}
17+
/>
2518
);
2619
};

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,

0 commit comments

Comments
 (0)