📦 SETUP • ⚙️ CONFIGURATION • ️️️🛰️ FEATURES
Tired of sluggish websites and SEO headaches? Unleash the power of lightning-fast performance and built-in optimization with this Astro template builder! Crafted for developers who value speed and simplicity, this robust toolkit empowers you to build stunning websites that soar in search engines and captivate users. Ditch the struggle and focus on what matters most - crafting impactful content that drives engagement. Welcome to the future of web development - where SEO and performance work hand-in-hand. ( Back to top ) |
( Back to top )
-
Astro
- Astro Framework -
Typescript
- Extremely strict type checking -
Sass
- Css framework for ui development -
Clean arquitecture
- For clean code and scalablility -
SEO
- SEO meta data, open graph and more -
i18n
- Internationalization and translations -
Linter
- Linter and formatting all kind of files -
Git
- Control version and more -
Configuration
- Vscode, env variables and more -
Components
-
Performance
-
Bun
- Fast package manager -
Perfect lighthouse score
- Because performance matters
( Back to top )
( Back to top )
After cloning the repo run this command to install all the dependencies.
bun i
( Back to top )
The configuration needed for this project is to set up the env variables and also the site configuration object here are the examples:
This file is located in src/global/configuration/site_configuration.ts
siteName
- Global title of the webpagedescription
- Global description of the webpageautor
- Author object that appears in a meta tagauthor.name
- Name of the authorauthor.email
- Email of the authorauthor.web
- Web of the author
copyright
- Copyright of the owner of the websitegoogleAnalyticId
- Id of the google analyticsdefaultLocale
- Default locale of the webpagelanguages
- Object with all the languages you want to supportexample
-languages: { en: 'English' }
This environment variables are located in src/global/env/**.env
file: .example.dev.env
PORT=4321
BASE_URL=http://localhost:$PORT
file: .example.prod.env
BASE_URL=
file: .example.staging.env
PORT=4321
BASE_URL=http://localhost:$PORT
1.- To start using i18n in this project you have to add the languages you want to support in the configuration file src/global/configuration/site_configuration.ts
, here you will find an object with the key languages
, also remenber to ser the default language to your preferences, you can set the languages like this:
const siteConfiguration =
{
defaultLanguage: 'en',
languages:
{
en: 'English',
es: 'Español'
}
}
2.- Next you will create in the src/pages
a directory called [language]
, here you will duplicate and put all the pages of your project, this is an example:
- /pages
- /[language]
- about-us.astro
- index.astro
- 404.astro
- about-us.astro
- index.astro
3.- The pages inside this directory will need to add an aditionnal validation for know if the language is correct and it is listeng in the configuration, you can add tis like this
pages/[language]/index.astro
---
import { getStaticLanguage } from '@global/util/language';
export const getStaticPaths = getStaticLanguage;
---
4.- Next you will create the translation files, we recommend to use ts files instead of json but you can aslo use json files
const aboutUsLocale =
{
en:
{
welcome: 'Hello world',
},
es:
{
welcome: 'Hola mundo',
}
};
export { aboutUsLocale };
5.- To end you will use this file and make the translation, use this inside you component page and not in the pages/**
components
---
import { getI18n, getStaticLanguage, getLanguageFromUrl } from '@global/util/language';
import { aboutUsLocale } from '@module/landing/locale/about_us';
const language = getLanguageFromUrl(Astro.url);
const i18n = getI18n(language, aboutUsLocale);
---
<h1>{i18n.welcome}</h1>
6.- Create the file src/middleware.ts
and add the following code, this will redirect the default language urls to the base urls, and examples of this is, /en/about-us
redirect to /about-us
import { getLanguagePathname, validateDefaultLanguage } from '@global/util/language';
import { defineMiddleware } from 'astro/middleware';
const onRequest = defineMiddleware(async (context, next) =>
{
if(validateDefaultLanguage(context.url))
{
const pathname = getLanguagePathname(context.url);
const redirectCode = 302;
return Response.redirect(new URL(pathname, context.url), redirectCode);
}
return next();
});
export { onRequest };
That's all the configuration nedeed for i18n in this project.
( Back to top )
Before installing all the dependencies you can run the project with
pnpm dev
To see the production ready page you can run
pnpm staging
Builds the app for production to the dist
folder.
It correctly bundles Solid in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes, also it compress all the assets and images in the dist folder.
Your app is ready to be deployed.
( Back to top )
The following scripts are available in the package.json
:
preinstall
: This script is for only allow pnpm as package managerpostinstall
: This script is for setting up the git hooks and validate the error after commit to githubdev
: This script is for see the webpage in dev modestaging
: This script is for see production, this run the env variables an set the webpage with all the settingsbuild-dev
: This script compile the project in dev modebuild
: This script is for build in productionlint
: This script is for format and lint all the fileslint-eslint
: This script is for lint ts, tsx and more fileslint-stylelint
: This script is for lint css files
( Back to top )
Here is the list of all the browser this website support
Firefox |
Safari |
Safari IOS |
Samsung |
Opera |
|
( Back to top )
Copyright © All rights reserved, developed by ElegantCoder and