A sample Next.js project for getting started with MDX, Theme UI, & Hack Club Theme.
- Import this repo to your coding environment of choice. Download it,
git clone, or use the GitHub import on Glitch/Repl.it. yarnto install dependencies.yarn devto start your server.- Start adding your own pages & components in their respective directories.
We’ve included an example theme switcher component at components/color-switcher.js,
which is included on every page through its inclusion in pages/_app.js.
Feel free to change it.
If you’re making a Hack Club HQ project, you’re allowed to use Hack Club’s font,
Phantom Sans.
To load it, simply uncomment the import '@hackclub/theme/fonts/reg-bold.css'
line in _app.js.
By default, the raw Hack Club Theme will be used.
If you’d like to edit the theme, we recommend making a theme file (perhaps at
lib/theme.js) along these lines:
importbasefrom'@hackclub/theme'consttheme=base// theme.fontSizes = […]// theme.fonts.heading = ''exportdefaultthemeSuper easy: yarn dev -p 5000
These template includes @hackclub/meta
for adding meta tags to Hack Club HQ sites. To set default meta tags across all pages,
add the following to pages/_app.js:
// import Head from 'next/head'// import Meta from '@hackclub/meta'<Metaas={Head}name="Hack Club"// site nametitle="Hackathons"// page titledescription="List of upcoming high school hackathons"// page descriptionimage="https://hackathons.hackclub.com/card.png"// large summary card image URLcolor="#ec3750"// theme colormanifest="/site.webmanifest"// link to site manifest/>If you’re not making a site for HQ, don’t use @hackclub/meta, since it adds
Hack Club’s favicons & info. Instead, we recommend making your own component,
perhaps at components/meta.js.
Example code
importHeadfrom'next/head'importthemefrom'@hackclub/theme'// or '../lib/theme'exportdefault({
name ='Your Company',
title ='Your Project',
description ='',
image ='https://yourproject.vercel.app/card.png',
url ='https://yourproject.vercel.app/'})=>(<Head><title>{title}</title><metaproperty="og:title"content={title}/><metaname="twitter:title"content={title}/><metaname="og:url"content={url}/><metaproperty="og:type"content="website"/><metaproperty="og:site_name"content={name}/><metaname="description"content={description}/><metaproperty="og:description"content={description}/><metaname="twitter:description"content={description}/><metaproperty="og:image"content={image}/><metaname="twitter:card"content="summary_large_image"/><metaname="twitter:image"content={image}/><metaname="msapplication-TileColor"content={theme.colors.primary}/><metaname="theme-color"content={theme.colors.primary}/></Head>)Hack Club HQ uses (& loves) Fathom Analytics for simple, privacy-focused analytics. (Check out our site’s analytics here.)
To add Fathom to your project, yarn add fathom-client, then you’ll need to
load it appropriately in pages/_app.js. The script is located at
https://aardvark.hackclub.com/script.js.
Example file with Fathom
importReact,{useEffect}from'react'import{useRouter}from'next/router'importNextAppfrom'next/app'importHeadfrom'next/head'importMetafrom'@hackclub/meta'import'@hackclub/theme/fonts/reg-bold.css'importthemefrom'../lib/theme'import{ThemeProvider}from'theme-ui'import*asFathomfrom'fathom-client'constApp=({ Component, pageProps })=>{constrouter=useRouter()useEffect(()=>{Fathom.load('YOURCODE',{includedDomains: ['hackclub.com'],url: 'https://aardvark.hackclub.com/script.js'})constonRouteChangeComplete=()=>Fathom.trackPageview()router.events.on('routeChangeComplete',onRouteChangeComplete)return()=>{router.events.off('routeChangeComplete',onRouteChangeComplete)}},[])return(<ThemeProvidertheme={theme}><Metaas={Head}/><Component{...pageProps}/></ThemeProvider>)}exportdefaultAppWe recommend using Vercel for deployment. It requires no configuration, is totally free for personal projects, and supports all the features of Next.js with the best performance. Refer to their documentation for more details.
You can also deploy your site to Netlify, which is also free. Refer to their documentation on the necessary configuration.