| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff 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 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,9 +1,9 @@ | |||
| 1 | 1 | import React from 'react' | |
| 2 | 2 | import { RootWrapper } from './src/components/RootWrapper' | |
| 3 | 3 | 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'); | ||
| 5 | 5 | ||
| 6 | - (typeof global !== 'undefined' ? global : window).Prism = Prism | ||
| 6 | + window.Prism = Prism | ||
| 7 | 7 | ||
| 8 | 8 | require('./src/components/highlights') | |
| 9 | 9 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,11 +1,11 @@ | |||
| 1 | - const path = require('path') | ||
| 1 | + import path from 'path'; | ||
| 2 | 2 | ||
| 3 | 3 | const visit = require('unist-util-visit') | |
| 4 | 4 | ||
| 5 | 5 | /** @type {import('unified').Plugin<Array<void>, import('hast').Root>} */ | |
| 6 | 6 | 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 } }) => { | ||
| 9 | 9 | if (node.tagName === 'code' && node.data && node.data.meta) { | |
| 10 | 10 | node.properties.meta = node.data.meta | |
| 11 | 11 | } | |
@@ -15,10 +15,12 @@ function rehypeMetaAsAttributes() { | |||
| 15 | 15 | ||
| 16 | 16 | module.exports = { | |
| 17 | 17 | pathPrefix: `${process.env.PATH_PREFIX}`, | |
| 18 | + graphqlTypegen: true, | ||
| 18 | 19 | siteMetadata: { | |
| 19 | 20 | title: "mcjava-wiki", | |
| 20 | - githubRepositoryURL: 'https://github.com/mcjava-wiki/mcjava-wiki', | ||
| 21 | + githubRepository: 'mcjava-wiki/mcjava-wiki', | ||
| 21 | 22 | githubDefaultBranch: 'main', | |
| 23 | + discordInviteCode: 'rqsKmmh89J', | ||
| 22 | 24 | sections: [ | |
| 23 | 25 | 'About', | |
| 24 | 26 | 'Basics', | |
| Original file line number | Diff line number | Diff 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'; | ||
| 7 | 10 | ||
| 8 | 11 | function createSchemaCustomization({ actions }) { | |
| 9 | 12 | const { createTypes } = actions | |
@@ -57,7 +60,6 @@ async function onPreBootstrap(options) { | |||
| 57 | 60 | } | |
| 58 | 61 | ||
| 59 | 62 | async function onCreateMdxNode({ node, getNode, actions }, options) { | |
| 60 | - | ||
| 61 | 63 | const { createNodeField } = actions | |
| 62 | 64 | const slug = node.frontmatter.slug || createFilePath({ node, getNode }) | |
| 63 | 65 | const pageType = /\/pages\/docs\//.test(node.internal.contentFilePath) | |
@@ -74,11 +76,11 @@ async function onCreateMdxNode({ node, getNode, actions }, options) { | |||
| 74 | 76 | const url = new URL(getSiteUrl(options)) | |
| 75 | 77 | url.pathname = slug | |
| 76 | 78 | ||
| 77 | - function getGithubLink(tld, route) { | ||
| 79 | + function getGithubLink(tld: string, route: string) { | ||
| 78 | 80 | const { | |
| 79 | 81 | 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, | ||
| 82 | 84 | } = options | |
| 83 | 85 | const repositoryURL = githubRepositoryURL | |
| 84 | 86 | if (!baseDirectory || !repositoryURL) return '' | |
@@ -89,22 +91,35 @@ async function onCreateMdxNode({ node, getNode, actions }, options) { | |||
| 89 | 91 | return `${repositoryURL}${route}${githubDefaultBranch}${relativePath}` | |
| 90 | 92 | } | |
| 91 | 93 | ||
| 92 | - const getData = async (url) => { | ||
| 94 | + const getData = async (url: URL | RequestInfo) => { | ||
| 93 | 95 | const response = await fetch(url); | |
| 94 | 96 | return response.text(); | |
| 95 | 97 | }; | |
| 96 | 98 | ||
| 99 | + interface Contributor { | ||
| 100 | + name: string; | ||
| 101 | + link: string; | ||
| 102 | + } | ||
| 103 | + | ||
| 97 | 104 | 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 | + } | ||
| 108 | 123 | }); | |
| 109 | 124 | ||
| 110 | 125 | return contributors; | |
@@ -178,22 +193,22 @@ async function onCreateMdxNode({ node, getNode, actions }, options) { | |||
| 178 | 193 | createNodeField({ | |
| 179 | 194 | name: 'editLink', | |
| 180 | 195 | node, | |
| 181 | - value: getGithubLink('dev', '/blob/'), | ||
| 196 | + value: getGithubLink(tlds.DEV, routes.BLOB), | ||
| 182 | 197 | }) | |
| 183 | 198 | ||
| 184 | 199 | } | |
| 185 | 200 | ||
| 186 | - async function onCreateNode(...args) { | ||
| 201 | + async function onCreateNode(...args: [CreateNodeArgs]) { | ||
| 187 | 202 | if (args[0].node.internal.type === 'Mdx') { | |
| 188 | - await onCreateMdxNode(...args) | ||
| 203 | + await onCreateMdxNode(...args, {}) | ||
| 189 | 204 | } | |
| 190 | 205 | } | |
| 191 | 206 | ||
| 192 | 207 | async function createPages({ graphql, actions, reporter }) { | |
| 193 | 208 | const { createPage, createRedirect } = actions | |
| 194 | 209 | ||
| 195 | 210 | const { data, errors } = await graphql(` | |
| 196 | - query { | ||
| 211 | + query CreatePages { | ||
| 197 | 212 | allMdx { | |
| 198 | 213 | edges { | |
| 199 | 214 | node { | |
@@ -223,11 +238,11 @@ async function createPages({ graphql, actions, reporter }) { | |||
| 223 | 238 | return | |
| 224 | 239 | } | |
| 225 | 240 | ||
| 226 | - const filteredEdges = data.allMdx.edges.filter((edge) => { | ||
| 241 | + const filteredEdges = data.allMdx.edges.filter((edge: { node: { parent: { sourceInstanceName: string; }; fields: { slug: any; }; }; }) => { | ||
| 227 | 242 | if (edge.node.parent.sourceInstanceName === 'default-page') { | |
| 228 | 243 | const { slug } = edge.node.fields | |
| 229 | 244 | 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, | ||
| 231 | 246 | ) | |
| 232 | 247 | return !hasCustom404 | |
| 233 | 248 | } | |
@@ -249,7 +264,7 @@ async function createPages({ graphql, actions, reporter }) { | |||
| 249 | 264 | path: node.fields.slug, | |
| 250 | 265 | component: path.resolve( | |
| 251 | 266 | __dirname, | |
| 252 | - `./src/templates/${node.fields.pageType}.js?__contentFilePath=${node.internal.contentFilePath}`, | ||
| 267 | + `./src/templates/${node.fields.pageType}.ts?__contentFilePath=${node.internal.contentFilePath}`, | ||
| 253 | 268 | ), | |
| 254 | 269 | context: { | |
| 255 | 270 | id: node.id, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,4 +13,4 @@ export const wrapPageElement = ({ element, props }) => { | |||
| 13 | 13 | ||
| 14 | 14 | export const onRenderBody = ({ setPreBodyComponents }) => { | |
| 15 | 15 | setPreBodyComponents([getColorModeInitScriptElement()]) | |
| 16 | - } | ||
| 16 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,7 +5,8 @@ | |||
| 5 | 5 | "scripts": { | |
| 6 | 6 | "develop": "gatsby develop", | |
| 7 | 7 | "build": "gatsby build", | |
| 8 | - "serve": "gatsby serve" | ||
| 8 | + "serve": "gatsby serve", | ||
| 9 | + "clean": "gatsby clean" | ||
| 9 | 10 | }, | |
| 10 | 11 | "dependencies": { | |
| 11 | 12 | "@docsearch/css": "^3.3.2", | |
@@ -47,9 +48,16 @@ | |||
| 47 | 48 | "unist-util-visit": "^2.0.3" | |
| 48 | 49 | }, | |
| 49 | 50 | "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", | ||
| 50 | 57 | "gatsby": "^5.5.0", | |
| 51 | 58 | "react": "^18.2.0", | |
| 52 | 59 | "react-dom": "^18.2.0", | |
| 53 | - "standard-version": "^9.5.0" | ||
| 60 | + "standard-version": "^9.5.0", | ||
| 61 | + "typescript": "^4.9.5" | ||
| 54 | 62 | } | |
| 55 | 63 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -102,7 +102,7 @@ export function AppHeader() { | |||
| 102 | 102 | return ( | |
| 103 | 103 | <OuterHeader> | |
| 104 | 104 | <ScreenContainer> | |
| 105 | - <NavSkipLink tabindex="0" href="#main"> | ||
| 105 | + <NavSkipLink tabIndex={0} href="#main"> | ||
| 106 | 106 | Skip to content | |
| 107 | 107 | </NavSkipLink> | |
| 108 | 108 | <x.div row alignItems="center" flexWrap="nowrap" mx={-2}> | |
@@ -142,7 +142,9 @@ export function AppHeader() { | |||
| 142 | 142 | <DocSearch {...data.site.siteMetadata.docSearch} /> | |
| 143 | 143 | </x.div> | |
| 144 | 144 | ) : null} | |
| 145 | - <AppNav col="auto" px={2} /> | ||
| 145 | + <x.div col="auto" px={2}> | ||
| 146 | + <AppNav /> | ||
| 147 | + </x.div> | ||
| 146 | 148 | </x.div> | |
| 147 | 149 | </ScreenContainer> | |
| 148 | 150 | </OuterHeader> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,9 +1,23 @@ | |||
| 1 | 1 | import React from 'react' | |
| 2 | + import { graphql, useStaticQuery } from 'gatsby' | ||
| 2 | 3 | import { RiGithubFill, RiDiscordFill } from 'react-icons/ri' | |
| 3 | 4 | import { Nav, NavList, NavListItem, NavLink } from './Nav' | |
| 4 | 5 | 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 | + ` | ||
| 5 | 18 | ||
| 6 | 19 | export function AppNav() { | |
| 20 | + const data = useStaticQuery(AppNavQuery) | ||
| 7 | 21 | return ( | |
| 8 | 22 | <Nav> | |
| 9 | 23 | <NavList> | |
@@ -13,7 +27,7 @@ export function AppNav() { | |||
| 13 | 27 | <NavListItem> | |
| 14 | 28 | <NavLink | |
| 15 | 29 | as="a" | |
| 16 | - href="https://github.com/mcjava-wiki/mcjava-wiki" | ||
| 30 | + href={`https://${sites.GITHUB}.${tlds.COM}/${data.site.siteMetadata.githubRepository}`} | ||
| 17 | 31 | target="_blank" | |
| 18 | 32 | rel="noopener noreferrer" | |
| 19 | 33 | > | |
@@ -23,15 +37,17 @@ export function AppNav() { | |||
| 23 | 37 | <NavListItem> | |
| 24 | 38 | <NavLink | |
| 25 | 39 | as="a" | |
| 26 | - href="https://discord.gg/rqsKmmh89J" | ||
| 40 | + href={`https://${sites.DISCORD}.${tlds.GG}/${data.site.siteMetadata.discordInviteCode}`} | ||
| 27 | 41 | target="_blank" | |
| 28 | 42 | rel="noopener noreferrer" | |
| 29 | 43 | > | |
| 30 | 44 | <RiDiscordFill style={{ width: 24, height: 24 }} /> | |
| 31 | 45 | </NavLink> | |
| 32 | 46 | </NavListItem> | |
| 33 | 47 | <NavListItem> | |
| 34 | - <NavLink as={ColorModeSwitcher} /> | ||
| 48 | + <NavLink | ||
| 49 | + as={ColorModeSwitcher} | ||
| 50 | + /> | ||
| 35 | 51 | </NavListItem> | |
| 36 | 52 | </NavList> | |
| 37 | 53 | </Nav> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -65,8 +65,13 @@ const InnerButton = styled.buttonBox` | |||
| 65 | 65 | } | |
| 66 | 66 | ` | |
| 67 | 67 | ||
| 68 | + interface ButtonProps { | ||
| 69 | + variant?: 'primary' | 'secondary'; | ||
| 70 | + children: React.ReactNode; | ||
| 71 | + } | ||
| 72 | + | ||
| 68 | 73 | export const Button = React.forwardRef( | |
| 69 | - ({ variant = 'primary', children, ...props }, ref) => { | ||
| 74 | + ({ variant = 'primary', children, ...props }: ButtonProps, ref: any) => { | ||
| 70 | 75 | return ( | |
| 71 | 76 | <AriakitButton ref={ref} data-variant={variant}> | |
| 72 | 77 | {(buttonProps) => ( | |
| Back | FazBrowse Home | New Git URL |
0 commit comments