| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,5 @@ | |||
| 1 | 1 | import path from 'path'; | |
| 2 | + import type { GatsbyConfig } from "gatsby"; | ||
| 2 | 3 | ||
| 3 | 4 | const visit = require('unist-util-visit') | |
| 4 | 5 | ||
@@ -13,7 +14,7 @@ function rehypeMetaAsAttributes() { | |||
| 13 | 14 | } | |
| 14 | 15 | } | |
| 15 | 16 | ||
| 16 | - module.exports = { | ||
| 17 | + const config: GatsbyConfig = { | ||
| 17 | 18 | pathPrefix: `${process.env.PATH_PREFIX}`, | |
| 18 | 19 | graphqlTypegen: true, | |
| 19 | 20 | siteMetadata: { | |
@@ -168,3 +169,5 @@ module.exports = { | |||
| 168 | 169 | }, | |
| 169 | 170 | ], | |
| 170 | 171 | } | |
| 172 | + | ||
| 173 | + export default config; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,14 +1,14 @@ | |||
| 1 | - import { CreateNodeArgs } from "gatsby"; | ||
| 2 | - | ||
| 1 | + import { CreateNodeArgs, GatsbyNode, PageProps } from "gatsby"; | ||
| 3 | 2 | import fs from 'fs'; | |
| 4 | 3 | import path from 'path'; | |
| 5 | 4 | import { createFilePath } from 'gatsby-source-filesystem'; | |
| 6 | 5 | const { getSiteUrl } = require('./src/theme-options.ts') | |
| 7 | 6 | import { tlds, sites, routes } from './src/util/constants'; | |
| 8 | - const config = require('./gatsby-config.ts') | ||
| 9 | - import cheerio from 'cheerio'; | ||
| 7 | + import { load } from 'cheerio'; | ||
| 8 | + | ||
| 9 | + import config from './gatsby-config'; | ||
| 10 | 10 | ||
| 11 | - function createSchemaCustomization({ actions }) { | ||
| 11 | + export const createSchemaCustomization: GatsbyNode["createSchemaCustomization"] = ({ actions }) => { | ||
| 12 | 12 | const { createTypes } = actions | |
| 13 | 13 | const typeDefs = ` | |
| 14 | 14 | type NavItem { | |
@@ -52,7 +52,7 @@ function createDirectoryIfNotExists({ reporter }, pathname) { | |||
| 52 | 52 | } | |
| 53 | 53 | } | |
| 54 | 54 | ||
| 55 | - async function onPreBootstrap(options) { | ||
| 55 | + export const onPreBootstrap: GatsbyNode["onPreBootstrap"] = async (options) => { | ||
| 56 | 56 | // Create all required directories | |
| 57 | 57 | createDirectoryIfNotExists(options, 'pages') | |
| 58 | 58 | createDirectoryIfNotExists(options, 'pages/docs') | |
@@ -77,18 +77,20 @@ async function onCreateMdxNode({ node, getNode, actions }, options) { | |||
| 77 | 77 | url.pathname = slug | |
| 78 | 78 | ||
| 79 | 79 | function getGithubLink(tld: string, route: string) { | |
| 80 | + const siteMetadata = config.siteMetadata; | ||
| 81 | + if (!siteMetadata) return ''; | ||
| 80 | 82 | const { | |
| 81 | 83 | baseDirectory = path.resolve(__dirname, './'), | |
| 82 | - githubRepositoryURL = `https://${sites.GITHUB}.${tld}/${config.siteMetadata.githubRepository}`, | ||
| 83 | - githubDefaultBranch = config.siteMetadata.githubDefaultBranch, | ||
| 84 | + githubRepositoryURL = `https://${sites.GITHUB}.${tld}/${siteMetadata.githubRepository}`, | ||
| 85 | + githubDefaultBranch = siteMetadata.githubDefaultBranch, | ||
| 84 | 86 | } = options | |
| 85 | - const repositoryURL = githubRepositoryURL | ||
| 86 | - if (!baseDirectory || !repositoryURL) return '' | ||
| 87 | + const repositoryURL = githubRepositoryURL; | ||
| 88 | + if (!baseDirectory || !repositoryURL) return ''; | ||
| 87 | 89 | const relativePath = node.internal.contentFilePath.replace( | |
| 88 | 90 | baseDirectory, | |
| 89 | 91 | '', | |
| 90 | 92 | ) | |
| 91 | - return `${repositoryURL}${route}${githubDefaultBranch}${relativePath}` | ||
| 93 | + return `${repositoryURL}${route}${githubDefaultBranch}${relativePath}`; | ||
| 92 | 94 | } | |
| 93 | 95 | ||
| 94 | 96 | const getData = async (url: URL | RequestInfo) => { | |
@@ -103,7 +105,7 @@ async function onCreateMdxNode({ node, getNode, actions }, options) { | |||
| 103 | 105 | ||
| 104 | 106 | const getContributors = async () => { | |
| 105 | 107 | const contributorsHtml = await getData(getGithubLink(tlds.COM, routes.CONTRIBUTORS_LIST)); | |
| 106 | - const $ = cheerio.load(contributorsHtml); | ||
| 108 | + const $ = load(contributorsHtml); | ||
| 107 | 109 | ||
| 108 | 110 | const contributors: Contributor[] = []; | |
| 109 | 111 | $(".avatar").each((_i: any, element: any) => { | |
@@ -198,21 +200,25 @@ async function onCreateMdxNode({ node, getNode, actions }, options) { | |||
| 198 | 200 | ||
| 199 | 201 | } | |
| 200 | 202 | ||
| 201 | - async function onCreateNode(...args: [CreateNodeArgs]) { | ||
| 203 | + export const onCreateNode: GatsbyNode["onCreateNode"] = async (...args: [CreateNodeArgs]) => { | ||
| 202 | 204 | if (args[0].node.internal.type === 'Mdx') { | |
| 203 | 205 | await onCreateMdxNode(...args, {}) | |
| 204 | 206 | } | |
| 205 | 207 | } | |
| 206 | 208 | ||
| 207 | - async function createPages({ graphql, actions, reporter }) { | ||
| 208 | - const { createPage, createRedirect } = actions | ||
| 209 | + export const createPages: GatsbyNode["createPages"] = async ({ graphql, actions, reporter }) => { | ||
| 210 | + const { createPage, createRedirect } = actions; | ||
| 209 | 211 | ||
| 210 | - const { data, errors } = await graphql(` | ||
| 212 | + const allMdx: { | ||
| 213 | + errors?: any; | ||
| 214 | + data?: Queries.CreatePagesQuery; | ||
| 215 | + } = await graphql(` | ||
| 211 | 216 | query CreatePages { | |
| 212 | 217 | allMdx { | |
| 213 | 218 | edges { | |
| 214 | 219 | node { | |
| 215 | 220 | id | |
| 221 | + frontmatter | ||
| 216 | 222 | fields { | |
| 217 | 223 | slug | |
| 218 | 224 | pageType | |
@@ -232,14 +238,20 @@ async function createPages({ graphql, actions, reporter }) { | |||
| 232 | 238 | } | |
| 233 | 239 | `) | |
| 234 | 240 | ||
| 235 | - if (errors) { | ||
| 241 | + if (allMdx.errors) { | ||
| 236 | 242 | reporter.panicOnBuild(`Error while running GraphQL query.`) | |
| 237 | - console.log(errors) | ||
| 243 | + console.log(allMdx.errors) | ||
| 238 | 244 | return | |
| 239 | 245 | } | |
| 240 | 246 | ||
| 241 | - const filteredEdges = data.allMdx.edges.filter((edge: { node: { parent: { sourceInstanceName: string; }; fields: { slug: any; }; }; }) => { | ||
| 242 | - if (edge.node.parent.sourceInstanceName === 'default-page') { | ||
| 247 | + const data = allMdx.data; | ||
| 248 | + if (!data) return; | ||
| 249 | + | ||
| 250 | + const filteredEdges = data.allMdx.edges.filter((edge: Queries.CreatePagesQuery["allMdx"]["edges"][0]) => { | ||
| 251 | + const parent = edge.node.parent; | ||
| 252 | + if (!parent) return true; | ||
| 253 | + if (typeof parent === "object" && "sourceInstanceName" in parent && parent.sourceInstanceName === 'default-page') { | ||
| 254 | + if (!edge.node.fields) return true; | ||
| 243 | 255 | const { slug } = edge.node.fields | |
| 244 | 256 | const hasCustom404 = data.allMdx.edges.find( | |
| 245 | 257 | (_edge: { node: any; }) => edge !== _edge && _edge.node.fields.slug === slug, | |
@@ -251,6 +263,7 @@ async function createPages({ graphql, actions, reporter }) { | |||
| 251 | 263 | ||
| 252 | 264 | // Create pages | |
| 253 | 265 | filteredEdges.forEach(({ node }) => { | |
| 266 | + if (!node.fields || !node.fields.slug) return; | ||
| 254 | 267 | if (node.fields.redirect) { | |
| 255 | 268 | createRedirect({ | |
| 256 | 269 | fromPath: node.fields.slug, | |
@@ -275,7 +288,7 @@ async function createPages({ graphql, actions, reporter }) { | |||
| 275 | 288 | }) | |
| 276 | 289 | } | |
| 277 | 290 | ||
| 278 | - const pluginOptionsSchema = (/** @type {{ Joi: import('joi') }} */ { Joi }) => { | ||
| 291 | + export const pluginOptionsSchema: GatsbyNode["pluginOptionsSchema"] = (/** @type {{ Joi: import('joi') }} */ { Joi }) => { | ||
| 279 | 292 | return Joi.object({ | |
| 280 | 293 | // Validate that the anonymize option is defined by the user and is a boolean | |
| 281 | 294 | name: Joi.string().required(), | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -96,7 +96,7 @@ function useLogo(logos) { | |||
| 96 | 96 | } | |
| 97 | 97 | ||
| 98 | 98 | export function AppHeader() { | |
| 99 | - const data = useStaticQuery(AppHeaderQuery) | ||
| 99 | + const data: Queries.AppHeaderQuery = useStaticQuery(AppHeaderQuery) | ||
| 100 | 100 | const logo = useLogo(data.logos.nodes) | |
| 101 | 101 | ||
| 102 | 102 | return ( | |
@@ -121,7 +121,7 @@ export function AppHeader() { | |||
| 121 | 121 | px={2} | |
| 122 | 122 | height={32} | |
| 123 | 123 | src={logo.publicURL} | |
| 124 | - alt={data.site.siteMetadata.title} | ||
| 124 | + alt={data?.site?.siteMetadata?.title} | ||
| 125 | 125 | /> | |
| 126 | 126 | ) : ( | |
| 127 | 127 | <x.h2 | |
@@ -132,12 +132,12 @@ export function AppHeader() { | |||
| 132 | 132 | fontSize={18} | |
| 133 | 133 | m={0} | |
| 134 | 134 | > | |
| 135 | - {data.site.siteMetadata.title} | ||
| 135 | + {data?.site?.siteMetadata?.title} | ||
| 136 | 136 | </x.h2> | |
| 137 | 137 | )} | |
| 138 | 138 | </NavLink> | |
| 139 | 139 | </x.div> | |
| 140 | - {data.site.siteMetadata.docSearch ? ( | ||
| 140 | + {data?.site?.siteMetadata?.docSearch ? ( | ||
| 141 | 141 | <x.div col="auto" px={2} display={{ xs: 'none', md: 'block' }}> | |
| 142 | 142 | <DocSearch {...data.site.siteMetadata.docSearch} /> | |
| 143 | 143 | </x.div> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,7 +17,7 @@ const AppNavQuery = graphql` | |||
| 17 | 17 | ` | |
| 18 | 18 | ||
| 19 | 19 | export function AppNav() { | |
| 20 | - const data = useStaticQuery(AppNavQuery) | ||
| 20 | + const data: Queries.AppNavQuery = useStaticQuery(AppNavQuery) | ||
| 21 | 21 | return ( | |
| 22 | 22 | <Nav> | |
| 23 | 23 | <NavList> | |
@@ -27,7 +27,7 @@ export function AppNav() { | |||
| 27 | 27 | <NavListItem> | |
| 28 | 28 | <NavLink | |
| 29 | 29 | as="a" | |
| 30 | - href={`https://${sites.GITHUB}.${tlds.COM}/${data.site.siteMetadata.githubRepository}`} | ||
| 30 | + href={`https://${sites.GITHUB}.${tlds.COM}/${data?.site?.siteMetadata?.githubRepository}`} | ||
| 31 | 31 | target="_blank" | |
| 32 | 32 | rel="noopener noreferrer" | |
| 33 | 33 | > | |
@@ -37,7 +37,7 @@ export function AppNav() { | |||
| 37 | 37 | <NavListItem> | |
| 38 | 38 | <NavLink | |
| 39 | 39 | as="a" | |
| 40 | - href={`https://${sites.DISCORD}.${tlds.GG}/${data.site.siteMetadata.discordInviteCode}`} | ||
| 40 | + href={`https://${sites.DISCORD}.${tlds.GG}/${data?.site?.siteMetadata?.discordInviteCode}`} | ||
| 41 | 41 | target="_blank" | |
| 42 | 42 | rel="noopener noreferrer" | |
| 43 | 43 | > | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -71,7 +71,7 @@ interface ButtonProps { | |||
| 71 | 71 | } | |
| 72 | 72 | ||
| 73 | 73 | export const Button = React.forwardRef( | |
| 74 | - ({ variant = 'primary', children, ...props }: ButtonProps, ref: any) => { | ||
| 74 | + ({ variant = 'primary', children, ...props }: ButtonProps, ref: React.Ref<HTMLButtonElement>) => { | ||
| 75 | 75 | return ( | |
| 76 | 76 | <AriakitButton ref={ref} data-variant={variant}> | |
| 77 | 77 | {(buttonProps) => ( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,7 +11,7 @@ function getInverseMode(mode: 'light' | 'dark') { | |||
| 11 | 11 | return mode === 'light' ? 'dark' : 'light' | |
| 12 | 12 | } | |
| 13 | 13 | ||
| 14 | - export const ColorModeSwitcher = React.forwardRef((props, ref: any) => { | ||
| 14 | + export const ColorModeSwitcher = React.forwardRef((props, ref: React.Ref<HTMLButtonElement>) => { | ||
| 15 | 15 | const [mode, setMode] = useColorMode() as ['light' | 'dark', (mode: 'light' | 'dark') => void] | |
| 16 | 16 | const Icon = modeIcons[mode] | |
| 17 | 17 | return ( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -145,12 +145,19 @@ const DocSearchQuery = graphql` | |||
| 145 | 145 | ||
| 146 | 146 | function MobileSidebar({ children }) { | |
| 147 | 147 | const dialog = useDialogState({ animated: true }) | |
| 148 | - const data = useStaticQuery(DocSearchQuery) | ||
| 148 | + const data: Queries.DocSearchQuery = useStaticQuery(DocSearchQuery) | ||
| 149 | + if (!data.site || !data.site.siteMetadata) return null; | ||
| 150 | + const docSearch = data.site.siteMetadata.docSearch; | ||
| 151 | + if (!docSearch) return null; | ||
| 149 | 152 | return ( | |
| 150 | 153 | <> | |
| 151 | 154 | <Dialog state={dialog} as={SidebarDialog}> | |
| 152 | 155 | <div style={{paddingLeft: 20, paddingTop: 20}}> | |
| 153 | - <DocSearch {...data.site.siteMetadata.docSearch} /> | ||
| 156 | + <DocSearch | ||
| 157 | + apiKey={docSearch.apiKey} | ||
| 158 | + indexName={docSearch.indexName} | ||
| 159 | + appId={docSearch.appId} | ||
| 160 | + /> | ||
| 154 | 161 | </div> | |
| 155 | 162 | {children} | |
| 156 | 163 | </Dialog> | |
@@ -198,7 +205,7 @@ function PrevNextLinks({ editLink, ...props }: { navGroups: any; } & { [x: strin | |||
| 198 | 205 | ||
| 199 | 206 | export function DocLayout({ children, tableOfContents, editLink, contributors, ...props }) { | |
| 200 | 207 | const upMd = useUp('md') | |
| 201 | - const sideNav = useSideNavState() | ||
| 208 | + const sideNav: any = useSideNavState() | ||
| 202 | 209 | return ( | |
| 203 | 210 | <PageLayout title={undefined} {...props}> | |
| 204 | 211 | <ScreenContainer px={0}> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,7 +11,7 @@ const InnerFeature = styled.box` | |||
| 11 | 11 | padding-right: 5 !important; | |
| 12 | 12 | ` | |
| 13 | 13 | ||
| 14 | - export const Feature = React.forwardRef((props, ref: any) => ( | ||
| 14 | + export const Feature = React.forwardRef((props, ref: React.Ref<HTMLDivElement>) => ( | ||
| 15 | 15 | <InnerFeature | |
| 16 | 16 | ref={ref} | |
| 17 | 17 | col={{ xs: 1, md: 1 / 4 }} | |
@@ -43,15 +43,15 @@ const InnerFeatureImage = styled.img` | |||
| 43 | 43 | margin-top: 3; | |
| 44 | 44 | ` | |
| 45 | 45 | ||
| 46 | - export const FeatureImage = React.forwardRef((props, ref: any) => ( | ||
| 46 | + export const FeatureImage = React.forwardRef((props, ref: React.Ref<HTMLImageElement>) => ( | ||
| 47 | 47 | <InnerFeatureImage ref={ref} width={48} height={48} {...props} /> | |
| 48 | 48 | )) | |
| 49 | 49 | ||
| 50 | - export const FeatureList = React.forwardRef((props, ref: any) => ( | ||
| 50 | + export const FeatureList = React.forwardRef((props, ref: React.Ref<HTMLDivElement>) => ( | ||
| 51 | 51 | <ScreenContainer ref={ref} row my={-4} px={3} {...props} /> | |
| 52 | 52 | )) | |
| 53 | 53 | ||
| 54 | - export const FeatureSection = React.forwardRef((props, ref: any) => ( | ||
| 54 | + export const FeatureSection = React.forwardRef((props, ref: React.Ref<HTMLElement>) => ( | ||
| 55 | 55 | <x.section | |
| 56 | 56 | ref={ref} | |
| 57 | 57 | py={4} | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,5 @@ | |||
| 1 | 1 | import React from 'react' | |
| 2 | - import { graphql, useStaticQuery } from 'gatsby' | ||
| 2 | + import { graphql, useStaticQuery } from 'gatsby' | ||
| 3 | 3 | import { Seo } from './Seo' | |
| 4 | 4 | ||
| 5 | 5 | const HeadQuery = graphql` | |
@@ -13,13 +13,13 @@ const HeadQuery = graphql` | |||
| 13 | 13 | ` | |
| 14 | 14 | ||
| 15 | 15 | export function Head({ title }) { | |
| 16 | - const data = useStaticQuery(HeadQuery) | ||
| 16 | + const data: Queries.HeadQueryQuery = useStaticQuery(HeadQuery) | ||
| 17 | 17 | return ( | |
| 18 | 18 | <Seo | |
| 19 | 19 | title={ | |
| 20 | 20 | title | |
| 21 | - ? `${title} - ${data.site.siteMetadata.title}` | ||
| 22 | - : data.site.siteMetadata.title | ||
| 21 | + ? `${title} - ${data?.site?.siteMetadata?.title}` | ||
| 22 | + : data?.site?.siteMetadata?.title | ||
| 23 | 23 | } | |
| 24 | 24 | /> | |
| 25 | 25 | ) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -72,7 +72,7 @@ const InnerHero = styled(ScreenContainer)` | |||
| 72 | 72 | ` | |
| 73 | 73 | ||
| 74 | 74 | export const Hero = React.forwardRef( | |
| 75 | - ({ backgroundImageURL, ...props }: { backgroundImageURL?: string }, ref: any) => { | ||
| 75 | + ({ backgroundImageURL, ...props }: { backgroundImageURL?: string }, ref: React.Ref<HTMLDivElement>) => { | ||
| 76 | 76 | if (typeof backgroundImageURL === 'undefined') { | |
| 77 | 77 | return <InnerHero ref={ref} {...props} /> | |
| 78 | 78 | } | |
@@ -87,7 +87,7 @@ export const Hero = React.forwardRef( | |||
| 87 | 87 | }, | |
| 88 | 88 | ) | |
| 89 | 89 | ||
| 90 | - export const HeroBody = React.forwardRef((props, ref: any) => { | ||
| 90 | + export const HeroBody = React.forwardRef((props, ref: React.Ref<HTMLDivElement>) => { | ||
| 91 | 91 | return <x.div ref={ref} w={{ md: 0.5 }} {...props} /> | |
| 92 | 92 | }) | |
| 93 | 93 | ||
@@ -97,7 +97,7 @@ export const HeroSection = styled.sectionBox` | |||
| 97 | 97 | padding-bottom: 5; | |
| 98 | 98 | ` | |
| 99 | 99 | ||
| 100 | - export const HeroActionList = React.forwardRef((props, ref: any) => { | ||
| 100 | + export const HeroActionList = React.forwardRef((props, ref: React.Ref<HTMLDivElement>) => { | ||
| 101 | 101 | return ( | |
| 102 | 102 | <x.div | |
| 103 | 103 | ref={ref} | |
@@ -109,6 +109,6 @@ export const HeroActionList = React.forwardRef((props, ref: any) => { | |||
| 109 | 109 | ) | |
| 110 | 110 | }) | |
| 111 | 111 | ||
| 112 | - export const HeroAction = React.forwardRef((props, ref: any) => { | ||
| 112 | + export const HeroAction = React.forwardRef((props, ref: React.Ref<HTMLDivElement>) => { | ||
| 113 | 113 | return <x.div ref={ref} col="auto" p={2} {...props} /> | |
| 114 | 114 | }) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments