- Clone the repo
git clone [email protected]:aimementoring/website.git
- Open the folder
cd website
- Install dependencies
yarn
- Run the project in development mode
yarn dev
- If you want to test the project in build mode (similar to production mode) you need to run
yarn build && yarn start
- Create a new folder inside pages folder, with the name of your page (that page is accessible from URL with exact name by default)
- Create a new index.js file inside that folder with your React component.
- It is really important to add the BasicLayout as a parent component, so you need to add in
render
method something like this:
render() {
return (
<Layout>
{/* YOUR COMPONENT HTML */}
</Layout>
);
}
- If you want to change the URL, there is a file called
server.js
and you can specify the URL you want to use there, the code is something like this:
server.get('/your-component-url', (req, res) => {
const pagePath = '/yourComponentFolder';
const queryParams = {};
return ssrCache({
req, res, pagePath, queryParams,
});
});
Use dynamic imports instead of importing directly every time you think it is possible to import the component dynamically. To do that, first you need to use a dynamic utils from next import dynamic from 'next/dynamic';
. After that, you can import a component dynamically using:
Good way to import components
const MyComponent = dynamic(() => import('../components/myComponent'));
Bad way to import components
import MyComponent from '../components/myComponent';
This is important because we can reduce the amount of lines and code for the first render, and we load the components asynchronously.
We use dynamic imports for React Components which has render method, and for UI libraries (e.g. Aime Blueprint component). It is important to use only in those cases, and we should avoid using it when we load data, functional libraries or methods, because it could break prerender, and also we want the data directly when we render the page for the SEO.
It is quite important to create small components and small pages, so we can have good performance on the website.
Instead of adding a long HTML in your render method on your page, you should break it down, and create small components from there that you can import in your page dynamically.
The main idea with that is:
- We can easily reuse code adding the same components on different pages.
- We can easily Unit test components and methods.
- Refactors and design changes are faster and easier.
- First render is faster because we load content asynchronously so we don't need to have the full page when we are navigating.
- It is easier to add and update styles with css modules because files are smaller.
If you want to test aws s3 command locally, you need first to install aws command, following next instructions:
curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"
unzip awscli-bundle.zip
sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
or you can install it with python, based on aws documentation
# Install pip3 if you don't have it yet
curl -O https://bootstrap.pypa.io/get-pip.py
python3 get-pip.py --user
# Install aws cli
pip3 install awscli --upgrade --user
After installation is finished, verify the installation has completed correctly with the following command:
pip3 install awscli --upgrade --user
Now follow next steps:
- From root folder of this project, run
cp -R .aws ~/.awd
to save credentials in our computer aws configure list
to see what credentials you have defined in your computer. Expected output should look like this:Name Value Type Location ---- ----- ---- -------- profile <not set> None None access_key ****************CNUG shared-credentials-file secret_key ****************v962 shared-credentials-file region ap-southeast-2 config-file ~/.aws/config
- Execute
sync:aws:next:staging
or any other command on aws to check if it works
- Don't forget to add PUBLIC_URL in environment variables on Heroku for Staging and Production, because are uploading next static folder there to improve the performance, and it is important to load those files from the CDN instead of loading them locally.
There are two folders on AWS where we store all our assets - images, fonts, files, etc. These are aimementoring-staging
(d2cl4o0mkg71rr
) and aimementoring
(d1muvgoqe3g8vw
).
To manage the content of reports, terms & conditions and stories we use Contentful. You can find the login for content editors in 1Password; contact your team leads to get access as a developer.
We use two different environments, staging
and master
.
(Check your .env
to make sure you're using staging
for development.)
Contentful has a content model. You can change it in the UI, but if you want to make bigger changes and migrate existing content, you might want to use migrations.
Migrations are written in Javascript. You can find some examples in the /migrations
folder.
You find more info here: https://www.contentful.com/developers/docs/tutorials/cli/scripting-migrations/
- To run Contentful migrations, you need to install the Contentful CLI.
$ yarn global add contentful-cli
- Then do
$ contentful login
, log into Contentful in your browser and paste the token. - Finally, run the migration you want to run:
contentful space migration --space-id SPACE_ID --environment-id 'staging' migrations/myMigration.js