This project is built with Contentful, Next.js, Tailwind CSS & Typescript.
- Node.js 22.23.4 or later
- Install
nvm
Follow nvm setup instructions here.
- Install Node.js locally
nvm install 22.23.4
nvm use 22.23.4
- Install
yarn
npm install yarn -g
- Install dependencies
Using --frozen-lockfile makes sure that the environment is consistent on any machine by installing the exact package versions listed in the yarn.lock.
yarn install --frozen-lockfile
-
Signup for a free Contentful account and create an organisation and within that create a space.
We called our organization OPTF and the space Website.
-
For the site to build correctly you need to import our Content models and assets into your Contentful space. We have created some example content so you can get comfortable with our Contentful setup.
-
Add your
space IDandcontent management tokeninside of contentful/config.json -
Run this command inside the root of this project
npx contentful space import --config contentful/config.json- For more information about importing/exporting in Contentful see here.
-
-
Setup your environment file. See our .env.example as a guide. Make sure to call the file
.env.local.
- For accessbility testing we use the axe-react plugin.
- We use the Headwind VSCode extension for sorting TailwindCSS classes.
- We use classnames to organise our classes into groups that combine at build time.
If you are new to Next.js, this is a helpful introduction: https://nextjs.org/docs
Now you can run the development server:
yarn devOpen http://localhost:3000 with your browser to see the OPTF homepage.
You can start editing the page by modifying pages/index.js. The page auto-updates as you edit the file.
Before a commit is accepted the staged changes will be formatted using prettier and linted using eslint. The commit will be reverted if files are formatted or lint errors are returned.
This project follows Conventional Commits
Commit messages will be checked using husky and commitlint.
- Use the
Link PreviewandMediacontent models for embedding content into blog posts. - If linking content that is on the site itself try to omit omit https://optf.org.
e.g.
https://optf.org/blog/onion-requests-session-new-message-routing-solution/=>/blog/onion-requests-session-new-message-routing-solution/. - To use superscript, subscript,
strikethroughsor style text use theMarkupcontent model.
- Try to use the next/image component in place of
imgtags where possible. It must have theunoptimizedprop:next exporthas no image optimizer. - If you want to make a link to a location on the website use the next/link component with a relative path. i.e.
https://optf.ngo/blog -> /blog
This helps with readability and is encouraged. Consider it to be a guideline and not a set of rules.
<div className={classNames(
"general classes here - colors, fonts, padding, margin etc",
"responsive class changes should have it's own string md: lg: etc."
"placeholder classes",
"animations, transforms, effect",
"pseudo classes i.e hover, focus, active, etc.",
"toggling classes i.e. NavMenu isExpanded"
)}></div>
.custom-class {
@apply general classes here - colors, fonts, padding, margin etc;
@apply responsive class changes should have it's own string md: lg: etc.;
@apply placeholder classes;
@apply animations, transforms, effect;
@apply pseudo classes i.e hover, focus, active, etc.;
@apply toggling classes i.e. NavMenu isExpanded;
}
We can't use template literals with classes if we want to purge (shrink) the CSS files at build time.
<div className="hover:bg-black hover:text-${bgColor}"></div> // Won't work in production
- tailwindlabs/tailwindcss#2209 (comment)
- https://tailwindcss.com/docs/optimizing-for-production#writing-purgeable-html
yarn build
This runs next build then next export, which writes a fully static site to out/. Serve that directory with any web server; no Node.js process runs in production. Content changes on Contentful need a rebuild.
next export does not apply headers, redirects or rewrites, so the web server must:
- serve clean URLs:
/blogfromblog.html,/fromindex.html, and redirect/path/to/path - serve blog posts at
/blog/:slugfrom:slug.html(/:slugalso works) - redirect (308)
/transparencyto/transparency-report, and the removed/contact-usand/feedback-and-ideaspages to/blog/the-optf-and-session - serve
404.htmlfor unknown paths - send the security headers, including the Content Security Policy
yarn build:staging builds the same export with staging metadata (https://staging.optf.ngo). It has no access control of its own; protect it at the web server if needed.
Distributed under the GNU GPLv3 License. See LICENSE for more information.
