FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Merge pull request #9 from mcjava-wiki/feature/ts · mcjava-wiki/mcjava-wiki@fb33bf3 · GitHub

Commit fb33bf3

Browse files
authored
Merge pull request #9 from mcjava-wiki/feature/ts
Migrate to typescript
2 parents 7602c7e + b5f713d commit fb33bf3

42 files changed

Lines changed: 3109 additions & 129 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.tsconfig‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"compilerOptions": {
3+
"target": "esnext",
4+
"lib": ["dom", "esnext"],
5+
"jsx": "react",
6+
"module": "esnext",
7+
"moduleResolution": "node",
8+
"allowJs": true,
9+
"outDir": "./dist",
10+
"esModuleInterop": true,
11+
"forceConsistentCasingInFileNames": true,
12+
"strict": true,
13+
"skipLibCheck": true
14+
},
15+
"exclude": ["node_modules", "public", ".cache"]
16+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from 'react'
22
import { RootWrapper } from './src/components/RootWrapper'
33
import { PageWrapper } from './src/components/PageWrapper'
4-
import Prism from 'prism-react-renderer/prism'
4+
const Prism = require('prism-react-renderer/prism') as typeof import('prismjs');
55

6-
(typeof global !== 'undefined' ? global : window).Prism = Prism
6+
window.Prism = Prism
77

88
require('./src/components/highlights')
99

gatsby-config.js renamed to gatsby-config.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
const path = require('path')
1+
import path from 'path';
22

33
const visit = require('unist-util-visit')
44

55
/** @type {import('unified').Plugin<Array<void>, import('hast').Root>} */
66
function rehypeMetaAsAttributes() {
7-
return (tree) => {
8-
visit(tree, 'element', (node) => {
7+
return (tree: any) => {
8+
visit(tree, 'element', (node: { tagName: string; data: { meta: any }; properties: { meta: any } }) => {
99
if (node.tagName === 'code' && node.data && node.data.meta) {
1010
node.properties.meta = node.data.meta
1111
}
@@ -15,10 +15,12 @@ function rehypeMetaAsAttributes() {
1515

1616
module.exports = {
1717
pathPrefix: `${process.env.PATH_PREFIX}`,
18+
graphqlTypegen: true,
1819
siteMetadata: {
1920
title: "mcjava-wiki",
20-
githubRepositoryURL: 'https://github.com/mcjava-wiki/mcjava-wiki',
21+
githubRepository: 'mcjava-wiki/mcjava-wiki',
2122
githubDefaultBranch: 'main',
23+
discordInviteCode: 'rqsKmmh89J',
2224
sections: [
2325
'About',
2426
'Basics',

gatsby-node.js renamed to gatsby-node.ts

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
const fs = require('fs')
2-
const path = require('path')
3-
const { createFilePath } = require('gatsby-source-filesystem')
4-
const { getSiteUrl } = require('./src/theme-options')
5-
const fetch = require('node-fetch');
6-
const cheerio = require('cheerio');
1+
import { CreateNodeArgs } from "gatsby";
2+
3+
import fs from 'fs';
4+
import path from 'path';
5+
import { createFilePath } from 'gatsby-source-filesystem';
6+
const { getSiteUrl } = require('./src/theme-options.ts')
7+
import { tlds, sites, routes } from './src/util/constants';
8+
const config = require('./gatsby-config.ts')
9+
import cheerio from 'cheerio';
710

811
function createSchemaCustomization({ actions }) {
912
const { createTypes } = actions
@@ -57,7 +60,6 @@ async function onPreBootstrap(options) {
5760
}
5861

5962
async function onCreateMdxNode({ node, getNode, actions }, options) {
60-
6163
const { createNodeField } = actions
6264
const slug = node.frontmatter.slug || createFilePath({ node, getNode })
6365
const pageType = /\/pages\/docs\//.test(node.internal.contentFilePath)
@@ -74,11 +76,11 @@ async function onCreateMdxNode({ node, getNode, actions }, options) {
7476
const url = new URL(getSiteUrl(options))
7577
url.pathname = slug
7678

77-
function getGithubLink(tld, route) {
79+
function getGithubLink(tld: string, route: string) {
7880
const {
7981
baseDirectory = path.resolve(__dirname, './'),
80-
githubRepositoryURL = `https://github.${tld}/mcjava-wiki/mcjava-wiki`,
81-
githubDefaultBranch = 'main',
82+
githubRepositoryURL = `https://${sites.GITHUB}.${tld}/${config.siteMetadata.githubRepository}`,
83+
githubDefaultBranch = config.siteMetadata.githubDefaultBranch,
8284
} = options
8385
const repositoryURL = githubRepositoryURL
8486
if (!baseDirectory || !repositoryURL) return ''
@@ -89,22 +91,35 @@ async function onCreateMdxNode({ node, getNode, actions }, options) {
8991
return `${repositoryURL}${route}${githubDefaultBranch}${relativePath}`
9092
}
9193

92-
const getData = async (url) => {
94+
const getData = async (url: URL | RequestInfo) => {
9395
const response = await fetch(url);
9496
return response.text();
9597
};
9698

99+
interface Contributor {
100+
name: string;
101+
link: string;
102+
}
103+
97104
const getContributors = async () => {
98-
const contributorsHtml = await getData(getGithubLink('com', '/contributors-list/'));
99-
const $ = cheerio.load(await contributorsHtml);
100-
const contributors = [];
101-
$(".avatar").each((i, element) => {
102-
const contributor = {};
103-
const name = $(element).parent().attr('href').slice(1);
104-
contributor.name = name ? name.trim() : '';
105-
const link = $(element).attr('src');
106-
contributor.link = link ? link : '';
107-
contributors.push(contributor);
105+
const contributorsHtml = await getData(getGithubLink(tlds.COM, routes.CONTRIBUTORS_LIST));
106+
const $ = cheerio.load(contributorsHtml);
107+
108+
const contributors: Contributor[] = [];
109+
$(".avatar").each((_i: any, element: any) => {
110+
const href = $(element).parent().attr('href');
111+
if (href) {
112+
const name = href.slice(1);
113+
const link = $(element).attr('src');
114+
const contributor: Contributor = {
115+
name: name ? name.trim() : '',
116+
link: link ? link : ''
117+
};
118+
119+
contributor.name = name ? name.trim() : '';
120+
contributor.link = link ? link : '';
121+
contributors.push(contributor);
122+
}
108123
});
109124

110125
return contributors;
@@ -178,22 +193,22 @@ async function onCreateMdxNode({ node, getNode, actions }, options) {
178193
createNodeField({
179194
name: 'editLink',
180195
node,
181-
value: getGithubLink('dev', '/blob/'),
196+
value: getGithubLink(tlds.DEV, routes.BLOB),
182197
})
183198

184199
}
185200

186-
async function onCreateNode(...args) {
201+
async function onCreateNode(...args: [CreateNodeArgs]) {
187202
if (args[0].node.internal.type === 'Mdx') {
188-
await onCreateMdxNode(...args)
203+
await onCreateMdxNode(...args, {})
189204
}
190205
}
191206

192207
async function createPages({ graphql, actions, reporter }) {
193208
const { createPage, createRedirect } = actions
194209

195210
const { data, errors } = await graphql(`
196-
query {
211+
query CreatePages {
197212
allMdx {
198213
edges {
199214
node {
@@ -223,11 +238,11 @@ async function createPages({ graphql, actions, reporter }) {
223238
return
224239
}
225240

226-
const filteredEdges = data.allMdx.edges.filter((edge) => {
241+
const filteredEdges = data.allMdx.edges.filter((edge: { node: { parent: { sourceInstanceName: string; }; fields: { slug: any; }; }; }) => {
227242
if (edge.node.parent.sourceInstanceName === 'default-page') {
228243
const { slug } = edge.node.fields
229244
const hasCustom404 = data.allMdx.edges.find(
230-
(_edge) => edge !== _edge && _edge.node.fields.slug === slug,
245+
(_edge: { node: any; }) => edge !== _edge && _edge.node.fields.slug === slug,
231246
)
232247
return !hasCustom404
233248
}
@@ -249,7 +264,7 @@ async function createPages({ graphql, actions, reporter }) {
249264
path: node.fields.slug,
250265
component: path.resolve(
251266
__dirname,
252-
`./src/templates/${node.fields.pageType}.js?__contentFilePath=${node.internal.contentFilePath}`,
267+
`./src/templates/${node.fields.pageType}.ts?__contentFilePath=${node.internal.contentFilePath}`,
253268
),
254269
context: {
255270
id: node.id,

gatsby-ssr.js renamed to gatsby-ssr.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ export const wrapPageElement = ({ element, props }) => {
1313

1414
export const onRenderBody = ({ setPreBodyComponents }) => {
1515
setPreBodyComponents([getColorModeInitScriptElement()])
16-
}
16+
}

‎package.json‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"scripts": {
66
"develop": "gatsby develop",
77
"build": "gatsby build",
8-
"serve": "gatsby serve"
8+
"serve": "gatsby serve",
9+
"clean": "gatsby clean"
910
},
1011
"dependencies": {
1112
"@docsearch/css": "^3.3.2",
@@ -47,9 +48,16 @@
4748
"unist-util-visit": "^2.0.3"
4849
},
4950
"devDependencies": {
51+
"@types/node": "^18.13.0",
52+
"@types/prismjs": "^1.26.0",
53+
"@types/react": "^18.0.28",
54+
"@types/react-dom": "^18.0.10",
55+
"@types/react-helmet": "^6.1.6",
56+
"@types/styled-components": "^5.1.26",
5057
"gatsby": "^5.5.0",
5158
"react": "^18.2.0",
5259
"react-dom": "^18.2.0",
53-
"standard-version": "^9.5.0"
60+
"standard-version": "^9.5.0",
61+
"typescript": "^4.9.5"
5462
}
5563
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export function AppHeader() {
102102
return (
103103
<OuterHeader>
104104
<ScreenContainer>
105-
<NavSkipLink tabindex="0" href="#main">
105+
<NavSkipLink tabIndex={0} href="#main">
106106
Skip to content
107107
</NavSkipLink>
108108
<x.div row alignItems="center" flexWrap="nowrap" mx={-2}>
@@ -142,7 +142,9 @@ export function AppHeader() {
142142
<DocSearch {...data.site.siteMetadata.docSearch} />
143143
</x.div>
144144
) : null}
145-
<AppNav col="auto" px={2} />
145+
<x.div col="auto" px={2}>
146+
<AppNav />
147+
</x.div>
146148
</x.div>
147149
</ScreenContainer>
148150
</OuterHeader>
Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
import React from 'react'
2+
import { graphql, useStaticQuery } from 'gatsby'
23
import { RiGithubFill, RiDiscordFill } from 'react-icons/ri'
34
import { Nav, NavList, NavListItem, NavLink } from './Nav'
45
import { ColorModeSwitcher } from './ColorModeSwitcher'
6+
import { tlds, sites } from '../util/constants'
7+
8+
const AppNavQuery = graphql`
9+
query AppNav {
10+
site {
11+
siteMetadata {
12+
githubRepository
13+
discordInviteCode
14+
}
15+
}
16+
}
17+
`
518

619
export function AppNav() {
20+
const data = useStaticQuery(AppNavQuery)
721
return (
822
<Nav>
923
<NavList>
@@ -13,7 +27,7 @@ export function AppNav() {
1327
<NavListItem>
1428
<NavLink
1529
as="a"
16-
href="https://github.com/mcjava-wiki/mcjava-wiki"
30+
href={`https://${sites.GITHUB}.${tlds.COM}/${data.site.siteMetadata.githubRepository}`}
1731
target="_blank"
1832
rel="noopener noreferrer"
1933
>
@@ -23,15 +37,17 @@ export function AppNav() {
2337
<NavListItem>
2438
<NavLink
2539
as="a"
26-
href="https://discord.gg/rqsKmmh89J"
40+
href={`https://${sites.DISCORD}.${tlds.GG}/${data.site.siteMetadata.discordInviteCode}`}
2741
target="_blank"
2842
rel="noopener noreferrer"
2943
>
3044
<RiDiscordFill style={{ width: 24, height: 24 }} />
3145
</NavLink>
3246
</NavListItem>
3347
<NavListItem>
34-
<NavLink as={ColorModeSwitcher} />
48+
<NavLink
49+
as={ColorModeSwitcher}
50+
/>
3551
</NavListItem>
3652
</NavList>
3753
</Nav>
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,13 @@ const InnerButton = styled.buttonBox`
6565
}
6666
`
6767

68+
interface ButtonProps {
69+
variant?: 'primary' | 'secondary';
70+
children: React.ReactNode;
71+
}
72+
6873
export const Button = React.forwardRef(
69-
({ variant = 'primary', children, ...props }, ref) => {
74+
({ variant = 'primary', children, ...props }: ButtonProps, ref: any) => {
7075
return (
7176
<AriakitButton ref={ref} data-variant={variant}>
7277
{(buttonProps) => (

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL