Skip to content

AhaLabs/tenk-template-nextjs

Repository files navigation

Exploration: TenK template using Next.js

Design goals for the frontend template used by tenkbay.com:

  1. static assets on a server
  2. internationalization
  3. good SEO
  4. automate-able – most NFT projects will not want to edit the actual code; editing text and picking some colors should be enough
  5. for projects which want more control, template should be straightforward to edit manually

How this code works

This codebase explores using Next.js, a static-site generator that uses React, to accomplish the above. It demonstrates accomplishing all the goals above, with some caveats:

  1. Start by looking at settings.json and the JSON files in the i18n folder.
  2. You'll see that these files are then used by lib/locales.ts
  3. pages/[locale].tsx then uses lib/locales.ts to generate a different landing page for each locale file, so in this case the site ends up with a /en page and a /es page.
  4. pages/index.tsx is mostly empty, just showing a list of languages ("View in English", "Ver en Español"), and automatically redirects to the user's preferred language if it's available.
  5. components/layout.tsx shows a language picker in the footer of the page.

Does this site accomplish the design goals above?

Mostly. Some caveats:

  • Not using built-in internationalization: as explained, this approach is using custom internationalization that mostly works because we are planning to have a single landing page for each language. If we were planning to have more complex routing, this might break down.

    Next.js does offer Internationalized Routing, but it does not work with next export, Next's full static-site generation mode

  • Uncustomizable lang: related to the above, Next.js does not allow customizing <html lang="en"> on each page. See pages/_document.tsx

  • Unoptimized images: Like Internationalized Routing, Next's default handling of images relies on at least some server-rendered components rather than being fully statically-generated. This attempts to use next-optimized-images as suggested by the Next.js team, but this is a community-created library and is poorly supported, and we haven't yet been able to get it to work.

How automating such a site would work

When a project wants to launch a new TenK site, they would fill out a form that includes all necessary fields in settings.json (which could include color choices) and at least one locale file, such as i18n/en.json. There could also be optional fields (think: additional home page sections could be generated by including a sections array in i18n/en.json).

When they submit this form, we could make API calls to GitHub to clone this repo, edit the necessary JSON files, update hero.png and other assets, and deploy the website (either to GitHub Pages or some other static-site hosting service such as Netlify).

This repo could by default live in the github.com/tenkbay organization, but if the project wants to make manual edits they could for the repo and deploy it themselves.

Contributing

Prereq: install NodeJS and yarn. Then:

  • Clone repo
  • yarn install
  • yarn dev and edit files to see your changes
  • yarn build and open docs/index.html to see if the built version looks correct
  • git push to the main branch to deploy an updated website