| 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,14 @@ | |||
| 1 | + { | ||
| 2 | + "compilerOptions": { | ||
| 3 | + "target": "es2016", | ||
| 4 | + "jsx": "react", | ||
| 5 | + "module": "commonjs", | ||
| 6 | + "allowJs": true, | ||
| 7 | + "outDir": "./dist", | ||
| 8 | + "esModuleInterop": true, | ||
| 9 | + "forceConsistentCasingInFileNames": true, | ||
| 10 | + "strict": true, | ||
| 11 | + "skipLibCheck": true | ||
| 12 | + }, | ||
| 13 | + "exclude": ["node_modules", "public", ".cache"] | ||
| 14 | + } | ||
| 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 | |
|---|---|---|---|
@@ -4,8 +4,8 @@ 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 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,9 +1,10 @@ | |||
| 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 cheerio from 'cheerio'; | ||
| 7 | 8 | ||
| 8 | 9 | function createSchemaCustomization({ actions }) { | |
| 9 | 10 | const { createTypes } = actions | |
@@ -74,7 +75,7 @@ async function onCreateMdxNode({ node, getNode, actions }, options) { | |||
| 74 | 75 | const url = new URL(getSiteUrl(options)) | |
| 75 | 76 | url.pathname = slug | |
| 76 | 77 | ||
| 77 | - function getGithubLink(tld, route) { | ||
| 78 | + function getGithubLink(tld: string, route: string) { | ||
| 78 | 79 | const { | |
| 79 | 80 | baseDirectory = path.resolve(__dirname, './'), | |
| 80 | 81 | githubRepositoryURL = `https://github.${tld}/mcjava-wiki/mcjava-wiki`, | |
@@ -89,22 +90,35 @@ async function onCreateMdxNode({ node, getNode, actions }, options) { | |||
| 89 | 90 | return `${repositoryURL}${route}${githubDefaultBranch}${relativePath}` | |
| 90 | 91 | } | |
| 91 | 92 | ||
| 92 | - const getData = async (url) => { | ||
| 93 | + const getData = async (url: URL | RequestInfo) => { | ||
| 93 | 94 | const response = await fetch(url); | |
| 94 | 95 | return response.text(); | |
| 95 | 96 | }; | |
| 96 | 97 | ||
| 98 | + interface Contributor { | ||
| 99 | + name: string; | ||
| 100 | + link: string; | ||
| 101 | + } | ||
| 102 | + | ||
| 97 | 103 | const getContributors = async () => { | |
| 98 | 104 | 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 $ = cheerio.load(contributorsHtml); | ||
| 106 | + | ||
| 107 | + const contributors: Contributor[] = []; | ||
| 108 | + $(".avatar").each((_i: any, element: any) => { | ||
| 109 | + const href = $(element).parent().attr('href'); | ||
| 110 | + if (href) { | ||
| 111 | + const name = href.slice(1); | ||
| 112 | + const link = $(element).attr('src'); | ||
| 113 | + const contributor: Contributor = { | ||
| 114 | + name: name ? name.trim() : '', | ||
| 115 | + link: link ? link : '' | ||
| 116 | + }; | ||
| 117 | + | ||
| 118 | + contributor.name = name ? name.trim() : ''; | ||
| 119 | + contributor.link = link ? link : ''; | ||
| 120 | + contributors.push(contributor); | ||
| 121 | + } | ||
| 108 | 122 | }); | |
| 109 | 123 | ||
| 110 | 124 | return contributors; | |
@@ -183,9 +197,9 @@ async function onCreateMdxNode({ node, getNode, actions }, options) { | |||
| 183 | 197 | ||
| 184 | 198 | } | |
| 185 | 199 | ||
| 186 | - async function onCreateNode(...args) { | ||
| 200 | + async function onCreateNode(...args: [CreateNodeArgs]) { | ||
| 187 | 201 | if (args[0].node.internal.type === 'Mdx') { | |
| 188 | - await onCreateMdxNode(...args) | ||
| 202 | + await onCreateMdxNode(...args, {}) | ||
| 189 | 203 | } | |
| 190 | 204 | } | |
| 191 | 205 | ||
@@ -223,11 +237,11 @@ async function createPages({ graphql, actions, reporter }) { | |||
| 223 | 237 | return | |
| 224 | 238 | } | |
| 225 | 239 | ||
| 226 | - const filteredEdges = data.allMdx.edges.filter((edge) => { | ||
| 240 | + const filteredEdges = data.allMdx.edges.filter((edge: { node: { parent: { sourceInstanceName: string; }; fields: { slug: any; }; }; }) => { | ||
| 227 | 241 | if (edge.node.parent.sourceInstanceName === 'default-page') { | |
| 228 | 242 | const { slug } = edge.node.fields | |
| 229 | 243 | const hasCustom404 = data.allMdx.edges.find( | |
| 230 | - (_edge) => edge !== _edge && _edge.node.fields.slug === slug, | ||
| 244 | + (_edge: { node: any; }) => edge !== _edge && _edge.node.fields.slug === slug, | ||
| 231 | 245 | ) | |
| 232 | 246 | return !hasCustom404 | |
| 233 | 247 | } | |
@@ -249,7 +263,7 @@ async function createPages({ graphql, actions, reporter }) { | |||
| 249 | 263 | path: node.fields.slug, | |
| 250 | 264 | component: path.resolve( | |
| 251 | 265 | __dirname, | |
| 252 | - `./src/templates/${node.fields.pageType}.js?__contentFilePath=${node.internal.contentFilePath}`, | ||
| 266 | + `./src/templates/${node.fields.pageType}.ts?__contentFilePath=${node.internal.contentFilePath}`, | ||
| 253 | 267 | ), | |
| 254 | 268 | context: { | |
| 255 | 269 | 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 | |
|---|---|---|---|
@@ -31,7 +31,9 @@ export function AppNav() { | |||
| 31 | 31 | </NavLink> | |
| 32 | 32 | </NavListItem> | |
| 33 | 33 | <NavListItem> | |
| 34 | - <NavLink as={ColorModeSwitcher} /> | ||
| 34 | + <NavLink | ||
| 35 | + as={ColorModeSwitcher} | ||
| 36 | + /> | ||
| 35 | 37 | </NavListItem> | |
| 36 | 38 | </NavList> | |
| 37 | 39 | </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) => ( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,7 @@ | |||
| 1 | 1 | import React from 'react' | |
| 2 | 2 | import rangeParser from 'parse-numeric-range'; | |
| 3 | 3 | import styled, { useTheme, th, up, css, useColorMode } from '@xstyled/styled-components' | |
| 4 | - import Highlight, { defaultProps } from 'prism-react-renderer' | ||
| 4 | + import Highlight, { defaultProps, Language, PrismTheme } from 'prism-react-renderer' | ||
| 5 | 5 | import { | |
| 6 | 6 | LiveProvider, | |
| 7 | 7 | LiveEditor, | |
@@ -55,12 +55,13 @@ const Pre = styled.pre` | |||
| 55 | 55 | ` | |
| 56 | 56 | ||
| 57 | 57 | // line highlighting | |
| 58 | - const calculateLinesToHighlight = (meta) => { | ||
| 58 | + const calculateLinesToHighlight = (meta: string) => { | ||
| 59 | 59 | const REhighlights = /highlights={([\d,-]+)}/ | |
| 60 | - if (REhighlights.test(meta)) { | ||
| 61 | - const strlineNumbers = REhighlights.exec(meta)[1] | ||
| 60 | + const match = REhighlights.exec(meta) | ||
| 61 | + if (match) { | ||
| 62 | + const strlineNumbers = match[1] | ||
| 62 | 63 | const lineNumbers = rangeParser(strlineNumbers) | |
| 63 | - return (index) => (lineNumbers.includes(index + 1)) | ||
| 64 | + return (index: number) => (lineNumbers.includes(index + 1)) | ||
| 64 | 65 | } else { | |
| 65 | 66 | return () => false | |
| 66 | 67 | } | |
@@ -79,10 +80,11 @@ const CodeLabel = styled.button` | |||
| 79 | 80 | background: #0891B2; | |
| 80 | 81 | color: #ffffff; | |
| 81 | 82 | ` | |
| 82 | - const getCodeTitle = (meta) => { | ||
| 83 | + const getCodeTitle = (meta: string) => { | ||
| 83 | 84 | const REtitle = /title={(.*?)}/ | |
| 84 | - if (REtitle.test(meta)) { | ||
| 85 | - const codeTitle = REtitle.exec(meta)[1] | ||
| 85 | + const match = REtitle.exec(meta) | ||
| 86 | + if (match) { | ||
| 87 | + const codeTitle = match[1] | ||
| 86 | 88 | return <CodeLabel>{codeTitle}</CodeLabel> | |
| 87 | 89 | } else { | |
| 88 | 90 | return () => false | |
@@ -139,7 +141,7 @@ export function LiveConfig({ modules }) { | |||
| 139 | 141 | return null | |
| 140 | 142 | } | |
| 141 | 143 | ||
| 142 | - function req(path) { | ||
| 144 | + function req(path: string | number) { | ||
| 143 | 145 | const dep = globalModules[path] | |
| 144 | 146 | ||
| 145 | 147 | if (!dep) { | |
@@ -150,7 +152,7 @@ function req(path) { | |||
| 150 | 152 | return dep | |
| 151 | 153 | } | |
| 152 | 154 | ||
| 153 | - function importToRequire(code) { | ||
| 155 | + function importToRequire(code: string) { | ||
| 154 | 156 | return ( | |
| 155 | 157 | code | |
| 156 | 158 | // { a as b } => { a: b } | |
@@ -181,15 +183,24 @@ function importToRequire(code) { | |||
| 181 | 183 | ) | |
| 182 | 184 | } | |
| 183 | 185 | ||
| 184 | - export function usePrismTheme() { | ||
| 185 | - const theme = useTheme() | ||
| 186 | - const [mode] = useColorMode() | ||
| 187 | - return th(`prism-theme-${mode === 'light' ? 'light' : 'dark'}`)({ theme }) | ||
| 186 | + export function usePrismTheme(): PrismTheme { | ||
| 187 | + const theme = useTheme(); | ||
| 188 | + const [mode] = useColorMode(); | ||
| 189 | + const prismTheme = th(`prism-theme-${mode === 'light' ? 'light' : 'dark'}`)({ theme }); | ||
| 190 | + | ||
| 191 | + if (typeof prismTheme !== 'object') { | ||
| 192 | + return { | ||
| 193 | + plain: {}, | ||
| 194 | + styles: [] | ||
| 195 | + }; | ||
| 196 | + } | ||
| 197 | + | ||
| 198 | + return prismTheme; | ||
| 188 | 199 | } | |
| 189 | 200 | ||
| 190 | 201 | ||
| 191 | 202 | // setup clipboard copy function | |
| 192 | - const copyToClipboard = (str) => { | ||
| 203 | + const copyToClipboard = (str: string) => { | ||
| 193 | 204 | const el = document.createElement("textarea") | |
| 194 | 205 | el.value = str | |
| 195 | 206 | el.setAttribute("readonly", "") | |
@@ -226,14 +237,15 @@ const CopyCode = styled.button` | |||
| 226 | 237 | ` | |
| 227 | 238 | ||
| 228 | 239 | export function Code({ children, lang = 'markup', metastring, meta }) { | |
| 229 | - const prismTheme = usePrismTheme() | ||
| 240 | + const prismTheme = usePrismTheme() as PrismTheme; | ||
| 241 | + | ||
| 230 | 242 | if (/live/.test(meta)) { | |
| 231 | 243 | return ( | |
| 232 | 244 | <LiveProvider | |
| 233 | 245 | code={children.trim()} | |
| 234 | 246 | transformCode={(code) => `${importToRequire(code)}`} | |
| 235 | 247 | scope={{ require: req }} | |
| 236 | - language={lang} | ||
| 248 | + language={lang as Language} | ||
| 237 | 249 | theme={prismTheme} | |
| 238 | 250 | noInline={/noInline/.test(meta)} | |
| 239 | 251 | > | |
@@ -242,7 +254,7 @@ export function Code({ children, lang = 'markup', metastring, meta }) { | |||
| 242 | 254 | as="div" | |
| 243 | 255 | style={{ borderTopLeftRadius: 0, borderTopRightRadius: 0 }} | |
| 244 | 256 | > | |
| 245 | - <LiveEditor padding={0} /> | ||
| 257 | + <LiveEditor /> | ||
| 246 | 258 | </Pre> | |
| 247 | 259 | <LiveError /> | |
| 248 | 260 | </LiveProvider> | |
@@ -254,30 +266,36 @@ export function Code({ children, lang = 'markup', metastring, meta }) { | |||
| 254 | 266 | <Highlight | |
| 255 | 267 | {...defaultProps} | |
| 256 | 268 | code={children.trim()} | |
| 257 | - language={lang} | ||
| 269 | + language={lang as Language} | ||
| 258 | 270 | theme={prismTheme} | |
| 259 | 271 | > | |
| 260 | 272 | {({ className, style, tokens, getLineProps, getTokenProps }) => ( | |
| 261 | 273 | <Pre className={className} style={style}> | |
| 262 | - {getCodeTitle(metastring)} | ||
| 263 | - <div> | ||
| 274 | + <div> | ||
| 275 | + <> | ||
| 276 | + {getCodeTitle(metastring)} | ||
| 277 | + <div> | ||
| 264 | 278 | <CopyCode onClick={handleClick}><FaClipboard/></CopyCode> | |
| 265 | - {tokens.map((line, i) => { | ||
| 266 | - const lineProps = getLineProps({ line, key: i }) | ||
| 267 | - if (shouldHighlightLine(i)) { | ||
| 268 | - lineProps.className = `${lineProps.className} highlight-line` | ||
| 269 | - } | ||
| 270 | - return ( | ||
| 271 | - <div {...lineProps}> | ||
| 272 | - <LineNo>{i + 1}</LineNo> | ||
| 273 | - {line.map((token, key) => ( | ||
| 274 | - <span {...getTokenProps({ token, key })} /> | ||
| 275 | - ))} | ||
| 276 | - </div> | ||
| 277 | - ) | ||
| 278 | - })} | ||
| 279 | + <div> | ||
| 280 | + {tokens.map((line, i) => { | ||
| 281 | + const lineProps = getLineProps({ line, key: i }) | ||
| 282 | + if (shouldHighlightLine(i)) { | ||
| 283 | + lineProps.className = `${lineProps.className} highlight-line` | ||
| 284 | + } | ||
| 285 | + return ( | ||
| 286 | + <div {...lineProps}> | ||
| 287 | + <LineNo>{i + 1}</LineNo> | ||
| 288 | + {line.map((token, key) => ( | ||
| 289 | + <span {...getTokenProps({ token, key })} /> | ||
| 290 | + ))} | ||
| 291 | + </div> | ||
| 292 | + ) | ||
| 293 | + })} | ||
| 279 | 294 | </div> | |
| 280 | - </Pre> | ||
| 295 | + </div> | ||
| 296 | + </> | ||
| 297 | + </div> | ||
| 298 | + </Pre> | ||
| 281 | 299 | )} | |
| 282 | 300 | </Highlight> | |
| 283 | 301 | ) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments