adonisjs / v5-docs

📚 Source code and documentation for the official docs website.
https://v5-docs.adonisjs.com
88 stars 138 forks source link
adonisjs documentation hacktoberfest


AdonisJS official documentation

Source code and documentation for the official documentation website hosted on docs.adonisjs.com

Setup

Follow the below mentioned steps to setup the project on your local.

We do not follow any build process for rendering markdown to HTML. Instead, we compile markdown files on every page request. This ensures, we do not have to run any background compilers to compile markdown and then re-compile everything on a single change. The process is as simple as

--> New HTTP request --> Finding markdown file for the url --> Compile and serve it

Environment variables

Following environment variables are required to start the development server or create the production build.

PORT=3333
HOST=0.0.0.0
NODE_ENV=development
APP_KEY=iPbHJ0Wdr8_hA4DLTj83lKedQP9I5rJO
CACHE_VIEWS=false
DEBUG_DOCS=true
ALGOLIA_API_KEY=
COPY_REDIRECTS_FILE=false
REPOSITORY_URL=https://github.com/adonisjs/docs.adonisjs.com

The ALGOLIA_API_KEY environment variable is optional and required only if you want to enable search.

If you are deploying a translated version of the docs, then set the COPY_REDIRECTS_FILE=false. Since the redirects file is applicable only for the official documentation to avoid breaking the preview.adonisjs.com URLs.

Content structure

The markdown content is saved inside the content directory and each documentation type (we call them zones) has its own subfolder.

The navigation for the website header and the sidebar is driven by the menu.json file inside each zone's subdirectory.

content
├── cookbooks
│   ├── menu.json
├── guides
│   ├── menu.json
├── reference
│   └── menu.json
└── releases
    ├── menu.json

The menu.json file has the following structure

{
  "name": "Database",
  "categories": [
    {
      "name": "root",
      "docs": [
        {
          "title": "Connection",
          "permalink": "database/connection",
          "contentPath": "database/connection.md",
        }
      ]
    }
  ]
}

Rendering HTML

We make use of a self written @dimerapp/content module to render markdown to HTML using Edge templates in the middle.

We begin by first converting Markdown to an AST and then render each node of the AST using Edge templates. This allow to spit custom markup. Checkout the ./resources/views/elements directory to see how we are using it.

The code blocks are rendered using the shiki. The module uses VsCode grammar and themes to process the code blocks. Also, code blocks are processed on the backend and the client receives formatted HTML.

Configuring @dimerapp/content

The @dimerapp/content module does not come with any CLI or opinions on how the content should be structured.

So we have to self configure @dimerapp/content module. This is done inside the start/content.ts file, which relies on the config/markdown.ts file.

CSS and frontend JavaScript

The styles are written in Vanilla CSS and stored inside the ./resources/css directory. To organize things a bit, we have split them inside multiple .css files.

We also make use of Alpine.js for adding small interactive components, like the header nav dropdown and the codegroup toggle.

The @hotwire/turbo is used to navigate between pages without doing a complete refresh.

Custom JS Hacks

Re-rendering HTML pages resets the scroll position of the sidebar, which is kind of annoying. So we make use of turbo events turbo:before-render and turbo:render to store the sidebar position and then restore it after navigation.

On first page visit, we scroll the active sidebar item into the view using the scrollIntoView method.

Deployment

Run the following command to create the production build.

npm run build

The output is written to the public directory and you can deploy it on any host capable of serving static files.

The official website is hosted on pages.cloudflare.com

Important environment variables

The ALGOLIA_API_KEY environment variable is optional and required only if you want to enable search.

If you are deploying a translated version of the docs, then set the COPY_REDIRECTS_FILE=false. Since the redirects file is applicable only for the official documentation to avoid breaking the preview.adonisjs.com URLs.

Translating docs to different languages

You are free to fork this repo and translate docs to different languages and publish them on a separate subdomain.

Disclaimer: The translated documentation is considered a community effort. The website and translations are/will never be supported or maintained by the core team.

Process for translating docs