This is the source code for the Capgo website, built with Astro.
To start the development server, run:
bun install
bun run devThe website runs as a Cloudflare Worker. Deployments are handled with wrangler deploy, driven by the wrangler.toml configuration in this repo.
The source code is licensed under the GNU AFFERO GENERAL PUBLIC license. See the LICENSE file for details.
Inside of your Astro project, you'll see the following folders and files:
/
βββ public/
β βββ favicon.svg
βββ src/
β βββ components/
β β βββ Card.astro
β βββ layouts/
β β βββ Layout.astro
β βββ pages/
β βββ index.astro
βββ package.json
Astro looks for .astro or .md files in the src/pages/ directory. Each page is exposed as a route based on its file name.
There's nothing special about src/components/, but that's where we like to put any Astro/React/Vue/Svelte/Preact components.
Any static assets, like images, can be placed in the public/ directory.
All commands are run from the root of the project, from a terminal:
| Command | Action |
|---|---|
bun install |
Installs dependencies |
bun run dev |
Starts local dev server at localhost:3000 |
bun run build |
Build your production site to ./dist/ |
bun run preview |
Preview your build locally, before deploying |
bun run preview:worker |
Run the Worker locally via wrangler dev |
bun run deploy |
Build and deploy the Worker to Cloudflare |
bun run astro ... |
Run CLI commands like astro add, astro check |
bun run astro -- --help |
Get help using the Astro CLI |
The website aims at having an automatic i18n done via various scripts in the scripts directory.
The translations.tsx script is used to translate the website content into the desired language. It has two methods to create translations, via OpenAI API or Anthropic API, and the other via api.datpmt.com. To use the OpenAI API method, make sure you have an OPENAI_API_KEY or ANTHROPIC_API_KEY as the environment variable set. To use the other API, just un-comment the translateText function call using it.
Now, let's say that you want to update translations or add a new locale, fr.
First, make sure to update the files scripts/setup_new_locale.tsx and scripts/generate_locale_translations.tsx to have the latest locale values as the following respectively.
const newLocale = 'fr'const locales = ['fr']Now to have translations generated for fr, you'd want to run:
bun run setup:new:locale: This script copies the existing files insrc/pagesdirectory tosrc/pages/frdirectory and makes sure to replace each reference tocontent/blogtocontent/fr/blog. Then, it copies thesrc/content/blogdirectory tosrc/content/fr/blogand makes sure to setlocalefrontmatter in each markdown file asfr. Then, it runs all the translation scripts mentioned below.bun run generate:locale:translations: This script uses the translate function to translate theen.ymlkey value pairs into the desired language, and creates afr.ymlfile.bun run generate:translation.ts: This script uses all the.ymlfiles in thelocalesdirectory to generate two files,src/services/locale.tsandsrc/services/translation.tsfiles with all the locales translations key value pair.bun run generate:blog:translations: This script uses all the.mdfiles in thesrc/content/blogdirectory to generate the translated version of the file in thesrc/content/fr/blogdirectory.bun run generate:plugin:translations: This script uses all the.mdfiles in thesrc/content/plugins-tutorialsdirectory to generate the translated version of the file in thesrc/content/fr/plugins-tutorialsdirectory.
