### Installing Dependencies with Make for GitLab Docs Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/setup.md This command installs all project dependencies managed by `mise` within the `docs-gitlab-com` directory. It's a crucial step for initial setup and for updating dependencies. ```shell make setup ``` -------------------------------- ### Initializing Self-Managed Installation Cards in Hugo Template Source: https://github.com/arqawa/docs-gitlab-com/blob/main/themes/gitlab-docs/layouts/partials/landing-page/installation.html This Go template snippet initializes the `$selfManagedCards` slice variable and populates it with dictionary objects. Each dictionary represents a distinct self-managed installation option, containing a localized title, URL, and description, intended for dynamic rendering on a web page. It relies on Hugo's `dict`, `slice`, `append`, and `T` (translation) functions. ```Go Template {{ $selfManagedCards := slice }} {{ $selfManagedCards = $selfManagedCards | append (dict \"title\" (T \"installation.installDockerTitle\") \"url\" \"install/docker/\" \"description\" (T \"installation.installDockerDesc\")) (dict \"title\" (T \"installation.compileSourceTitle\") \"url\" \"install/installation/\" \"description\" (T \"installation.compileSourceDesc\")) (dict \"title\" (T \"installation.installCloudProviderTitle\") \"url\" \"install/cloud\\_providers/\" \"description\" (T \"installation.installCloudProviderDesc\")) }} ``` -------------------------------- ### Compiling and Viewing GitLab Docs Locally Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/setup.md This command compiles the GitLab Docs site and starts a local server for previewing. The site becomes accessible at `http://localhost:1313`, with changes to content or source files visible immediately. ```shell make view ``` -------------------------------- ### Example `content/versions.json` Structure (JSON) Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/releases.md This JSON snippet provides an example of the `versions.json` file structure, which is updated during the release merge request process. It defines the `next`, `current`, `last_minor`, and `last_major` release versions for documentation. ```json [ { "next": "17.3", "current": "17.2", "last_minor": ["17.1", "17.0"], "last_major": ["16.11", "15.11"] } ] ``` -------------------------------- ### Generic JavaScript Code Example Source: https://github.com/arqawa/docs-gitlab-com/blob/main/__tests__/vale.md This is a placeholder JavaScript code block, illustrating a basic code snippet without specific functionality. It serves as an example of a JavaScript code fence within the documentation. ```javascript Example code here ``` -------------------------------- ### Starting Docker Daemon Manually on Linux (Shell) Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/releases.md This command provides the method to manually start the Docker daemon on Linux using `systemctl` when it's not running, which is a prerequisite for using Docker commands. ```shell sudo systemctl start docker ``` -------------------------------- ### Usage Example for `create-stable-branch` Make Target (Shell) Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/releases.md This example demonstrates how to use the `make create-stable-branch` command, specifying the `VERSION` variable. When executed, it creates a remote branch, triggers a parallel deployment, and builds a new Docker image for the specified GitLab version. ```shell make create-stable-branch VERSION=17.11 ``` -------------------------------- ### Starting Docker Daemon Manually on MacOS (Shell) Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/releases.md This command provides the method to manually start the Docker daemon on macOS when it's not running, which is a prerequisite for using Docker commands. ```shell dockerd ``` -------------------------------- ### Usage Example for `create-release-merge-request` Make Target (Shell) Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/releases.md This example shows how to invoke the `make create-release-merge-request` command, passing the `VERSION` variable. This action stashes local changes, updates the `main` branch, creates a release branch, modifies version lists, updates CI job variables, and pushes to create a merge request. ```shell make create-release-merge-request VERSION=17.11 ``` -------------------------------- ### Adding New Product Entry to products.yaml (YAML) Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/development.md This YAML snippet shows how to add a new product entry to `data/products.yaml`. It defines properties like `project_name`, `repo`, `content_dir`, `default_branch`, `clone_dir`, and `docs_dir` to configure how a new product's documentation is sourced and integrated into the site. ```YAML gitlab: project_name: 'GitLab' repo: 'https://gitlab.com/gitlab-org/gitlab.git' content_dir: 'doc' default_branch: 'master' clone_dir: '../gitlab' docs_dir: 'doc' ``` -------------------------------- ### Running Vite in Watch Mode for Frontend Development Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/development.md This command starts Vite in watch mode, which is essential for local frontend development. It automatically recompiles JavaScript and CSS code when changes are detected, enabling rapid iteration on frontend assets. ```Shell yarn run dev ``` -------------------------------- ### Mounting New Content Source in hugo.yaml (YAML) Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/development.md This YAML snippet demonstrates how to add a new content source to the `module.mounts` section of `hugo.yaml`. It maps a `source` directory (relative path to the cloned product documentation) to a `target` directory, typically `content`, for Hugo to process. ```YAML module: mounts: # # Add a new entry like this at the end: - source: ../my-new-product/docs target: content ``` -------------------------------- ### Using logger.Infof for Formatted Information (Go) Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/development.md This snippet illustrates the use of `logger.Infof` for logging informational messages with string substitution. The `f` suffix indicates a formatted string, allowing variables to be embedded in the log output. ```Go logger.Infof("Switching to %s branch...", defaultBranch) ``` -------------------------------- ### Installing Lefthook for Pre-Push Hooks - Shell Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/testing.md This command installs Lefthook, a Git hook manager, using `yarn`. Lefthook enables running tests automatically before pushing changes to the repository, ensuring code quality and adherence to standards prior to committing, thus preventing issues from being introduced into the main branch. ```shell yarn run lefthook install ``` -------------------------------- ### Configuring Colima Resources - Shell Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/development.md This configuration snippet for Colima, a Docker Desktop alternative, allows users to adjust the allocated CPU, disk, and memory resources for the virtual machine. Modifying these values can improve performance for resource-intensive Docker workloads on macOS. Note that disk changes only apply before VM creation. ```shell # Number of CPUs to be allocated to the virtual machine.\n# Default: 2\ncpu: 8\n\n# Size of the disk in GiB to be allocated to the virtual machine.\n# NOTE: changing this has no effect after the virtual machine has been created.\n# Default: 60\ndisk: 120\n\n# Size of the memory in GiB to be allocated to the virtual machine.\n# Default: 2\nmemory: 16 ``` -------------------------------- ### Running Docker Container with Port Mapping - Shell Source: https://github.com/arqawa/docs-gitlab-com/blob/main/themes/gitlab-docs/layouts/partials/archiveItem.html This command executes a Docker container in interactive mode, automatically removing it upon exit. It maps port 4000 from the host machine to port 4000 inside the container, using a dynamically provided image location. ```Shell docker run -it --rm -p 4000:4000 {{ .location }} ``` -------------------------------- ### Using logger.Fatal for Critical Errors (Go) Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/development.md This snippet demonstrates how to use the `logger.Fatal` function from the internal `logger` package to log critical errors and terminate the process. It is preferred over the default Go `log` package for consistent output. ```Go logger.Fatal("Could not pull updates!") ``` -------------------------------- ### Creating a Disclaimer Alert Box - Plaintext Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/shortcodes.md Provides an example of the self-closing `alert` shortcode with `type="disclaimer"` for displaying disclaimers. This is used for short, standalone disclaimers without additional content. ```plaintext {{< alert type="disclaimer" />}} ``` -------------------------------- ### Defining Main Content Block in Go Template Source: https://github.com/arqawa/docs-gitlab-com/blob/main/themes/gitlab-docs/layouts/_default/home.html This snippet defines the `main` content block using Go Template syntax, which is common in Hugo. It includes several partial templates to build a complete page layout, such as search, site sections, installation, reference architectures, support, and footer. The `.` context is passed to each partial. ```Go Template {{ define "main" }} {{ partial "landing-page/search.html" . }} {{ partial "landing-page/site-sections.html" . }} {{ partial "landing-page/installation.html" . }} {{ partial "landing-page/ref-architectures.html" . }} {{ partial "landing-page/support.html" . }} {{ partial "landing-page/footer.html" . }} {{ end }} ``` -------------------------------- ### Example Configuration for Documentation Versioning in JSON Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/architecture.md This JSON snippet illustrates the structure of the `content/versions.json` file, which defines the current, next, and previous major/minor versions of the documentation. This configuration is used to determine whether an 'archived documentation banner' should be displayed on a given page, based on whether the displayed version matches the 'current' entry or is built from the default branch. ```JSON [ { "next": "15.5", "current": "15.4", "last_minor": ["15.3", "15.2"], "last_major": ["14.10", "13.12"] } ] ``` -------------------------------- ### Applying Dependency Updates Locally with Make Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/dependencies.md This command ensures that all dependency updates are correctly applied in the local development environment. It is a crucial step to validate that upgrades work without errors and do not require additional manual intervention, ensuring a smooth setup for local development. ```Shell make setup ``` -------------------------------- ### Running Hugo in Development Mode for Live Reload Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/development.md This command runs Hugo in development mode, enabling live reloading of the documentation site. When combined with Vite's watch mode, it provides a seamless development experience where changes to both frontend assets and content are reflected instantly in the browser. ```Shell make view ``` -------------------------------- ### Adding Debug Output with Gum - Shell Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/development.md These commands provide structured debug output within shell scripts when the `gum` utility is available and `scripts-common.sh` has been sourced. They utilize array expansion (`[@]`) for robust command execution. Messages can use `...` for ongoing actions, `.` for success, and `!` for warnings/errors. ```shell "${GUM_INFO_CMD[@]}" "" ``` ```shell "${GUM_WARN_CMD[@]}" "" ``` ```shell "${GUM_ERROR_CMD[@]}" "" ``` -------------------------------- ### Adding Debug Output with Gum - Makefile Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/development.md These commands provide structured debug output within Makefiles when the `gum` utility is available. They allow for clear indication of general information, warnings, or errors using predefined `gum` commands. Messages can use `...` for ongoing actions, `.` for success, and `!` for warnings/errors. ```Makefile @$(GUM_INFO_CMD) "" ``` ```Makefile @$(GUM_WARN_CMD) "" ``` ```Makefile @$(GUM_ERROR_CMD) "" ``` -------------------------------- ### Adding Debug Output without Gum - Makefile Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/development.md These `printf` commands provide colored debug output in Makefiles when the `gum` utility is not available. They use predefined color variables (`INFO_COLOR_SET`, `WARN_COLOR_SET`, `ERROR_COLOR_SET`, `COLOR_RESET`) to format messages. Optionally, `@$(DATE_CMD)` can prefix output with a timestamp for better logging. ```Makefile @printf "$(INFO_COLOR_SET)INFO$(COLOR_RESET) \n" ``` ```Makefile @printf "$(WARN_COLOR_SET)WARN$(COLOR_RESET) \n" ``` ```Makefile @printf "$(ERROR_COLOR_SET)ERROR$(COLOR_RESET) \n" ``` -------------------------------- ### Conditional Free Trial URL Assignment in Hugo Source: https://github.com/arqawa/docs-gitlab-com/blob/main/themes/gitlab-docs/layouts/partials/header.html This Hugo template snippet initializes a default free trial URL. It then checks if the current page's file path starts with "omnibus/". If it does, the `$freeTrialUrl` variable is updated to a self-managed free trial URL, otherwise, the default URL is retained. ```Hugo {{ $freeTrialUrl := "https://gitlab.com/-/trial_registrations/new?glm_source=docs.gitlab.com&glm_content=navigation-cta-docs" }} {{ if .File }} {{ if hasPrefix .File.Path "omnibus/" }} {{ $freeTrialUrl = "https://about.gitlab.com/free-trial/?hosted=self-managed" }} {{ end }} {{ end }} ``` -------------------------------- ### Sourcing Common Scripts for Debugging - Shell Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/development.md This snippet sources the `scripts-common.sh` file, which is a prerequisite for using `gum`-based debug commands in shell scripts. It determines the parent directory of the current script to correctly locate and include the common script. This ensures that `gum` utility functions are available for subsequent logging. ```shell PARENT_PATH=$(dirname "$0") # shellcheck source=scripts/scripts-common.sh source "${PARENT_PATH}/scripts-common.sh" ``` -------------------------------- ### Adding Debug Output without Gum - Shell Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/development.md These `printf` commands provide colored debug output in shell scripts when the `gum` utility is not available. They use predefined color variables to format messages, similar to Makefile logging. Optionally, `"${DATE_CMD[@]}" | tr '\n' ' '` can prefix output with a timestamp for better logging. ```shell printf "${INFO_COLOR_SET}INFO${COLOR_RESET} \n" ``` ```shell printf "${WARN_COLOR_SET}WARN${COLOR_RESET} \n" ``` ```shell printf "${ERROR_COLOR_SET}ERROR${COLOR_RESET} \n" ``` -------------------------------- ### Cloning Documentation Projects with Make Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/setup.md This command clones all required documentation project repositories into the same location as `docs-gitlab-com`. It's used to pull content for the website build. ```shell make clone-docs-projects ``` -------------------------------- ### Deleting a Merge Request via cURL (Shell) Source: https://github.com/arqawa/docs-gitlab-com/blob/main/__tests__/vale.md This snippet demonstrates how to send a DELETE request to the GitLab API using cURL to remove a specific merge request. It requires the project ID and merge request IID as part of the URL path. ```shell curl --request DELETE --url https://gitlab.example.com/api/v4/projects/4/merge_requests/85 ``` -------------------------------- ### Cloning Documentation Projects with CI Emulation Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/setup.md This command clones documentation projects with a depth of 1, emulating the behavior of CI environments to improve performance by fetching less history. It's useful for local testing of CI-like scenarios. ```shell CI=true make clone-docs-projects ``` -------------------------------- ### Re-cloning Documentation Projects with Make Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/setup.md This command first removes any existing local checkouts of documentation projects before cloning them again. It's useful for ensuring a clean slate or resolving issues with existing repositories. ```shell REMOVE_BEFORE_CLONE=true make clone-docs-projects ``` -------------------------------- ### Cloning Documentation Projects via SSH with Make Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/setup.md This command clones documentation projects using SSH, allowing users with an SSH key to push commits back to `gitlab.com` without a password. It's an alternative to the default cloning method. ```shell USE_SSH=true make clone-docs-projects ``` -------------------------------- ### Updating All Documentation and GitLab Docs Projects Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/setup.md This command updates the local checkouts of all documentation projects, including the `docs-gitlab-com` project. It provides a comprehensive update for the entire local development environment. ```shell make update-all-projects ``` -------------------------------- ### Updating All Documentation Projects (Excluding GitLab Docs) Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/setup.md This command updates the local checkouts of all documentation projects, excluding the `docs-gitlab-com` project itself. It's used to keep content repositories current. ```shell make update-all-docs-projects ``` -------------------------------- ### Trusting mise.toml for GitLab Docs Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/setup.md This command is used to trust the `mise.toml` configuration file within the `docs-gitlab-com` directory. Trusting the file prevents warnings and ensures `mise` can manage dependencies correctly for the project. ```shell mise trust ``` -------------------------------- ### Configuring Search Backend and Navigation Links - Go Template Source: https://github.com/arqawa/docs-gitlab-com/blob/main/themes/gitlab-docs/layouts/partials/landing-page/search.html This snippet demonstrates how to use Go template syntax to conditionally set a search backend based on an environment variable and define a list of navigation links using translation functions and relative URLs. It requires a Go template engine to process. ```Go Template {{ T "landing-search.findGLAnswers"}} ===================================== {{ if or (eq (getenv "SEARCH\_BACKEND") "elastic") (eq (getenv "SEARCH\_BACKEND") "") }} {{ else }} {{ end }} * [{{ T "landing-search.getStarted" }}]({{ relURL ) * [{{ T "landing-search.cicdReference" }}]({{ relURL ) * [{{ T "landing-search.sshKeys" }}]({{ relURL ) * [{{ T "landing-search.personalAccessTokens" }}]({{ relURL ) * [{{ T "landing-search.commonGitCommands" }}]({{ relURL ) ``` -------------------------------- ### Updating Local GitLab Docs Checkout Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/setup.md This command updates the local checkout of the `docs-gitlab-com` project. It ensures the local repository is synchronized with the latest changes. ```shell make update ``` -------------------------------- ### Initializing Marketo Munchkin Tracking in JavaScript Source: https://github.com/arqawa/docs-gitlab-com/blob/main/themes/gitlab-docs/layouts/partials/analytics.html This JavaScript code initializes the Marketo Munchkin tracking script. It asynchronously loads 'munchkin.js' and calls 'Munchkin.init' with a specific account ID and configuration, enabling web activity tracking for Marketo. ```JavaScript (function() { var didInit = false; function initMunchkin() { if(didInit === false) { didInit = true; Munchkin.init('194-VVC-221', {"useBeaconAPI": true}); } } var s = document.createElement('script'); s.type = 'text/javascript'; s.async = true; s.src = 'https://munchkin.marketo.net/munchkin.js'; s.onreadystatechange = function() { if (this.readyState == 'complete' || this.readyState == 'loaded') { initMunchkin(); } }; s.onload = initMunchkin; document.getElementsByTagName('head')[0].appendChild(s); })(); ``` -------------------------------- ### Highlighting Code Blocks with Go Template Source: https://github.com/arqawa/docs-gitlab-com/blob/main/themes/gitlab-docs/layouts/_default/_markup/render-codeblock.html This Go template snippet processes the current context ('.') as a code block using the `transform.HighlightCodeBlock` function. The result, which includes the highlighted and wrapped code, is then outputted. The accompanying comment indicates its purpose is to add a clipboard copy toolbar to code samples, requiring synchronization with `themes/gitlab-docs/layouts/partials/archiveItem.html` for wrapper div consistency. ```Go Template {{/* Add the clipboard copy toolbar to code samples. Changes to the wrapper divs here should also be made in themes/gitlab-docs/layouts/partials/archiveItem.html. */}} {{- $result := transform.HighlightCodeBlock . -}} {{- $result.Wrapped -}} ``` -------------------------------- ### Initializing Data Structures and Counting Product Feature Flags (Go Template) Source: https://github.com/arqawa/docs-gitlab-com/blob/main/themes/gitlab-docs/layouts/shortcodes/feature-flags.html This Go Template snippet initializes several dictionaries (`uniqueGroupsWithCounts`, `uniqueMilestonesWithCounts`, `countDict`) and populates `countDict` by iterating through product feature flags to count the number of flags per product. It prepares data for subsequent rendering and aggregation. ```Go Template {{ $uniqueGroupsWithCounts := dict }} {{ $uniqueMilestonesWithCounts := dict }} {{ $products := .Site.Data.feature_flags.products}} {{ $countDict := dict }} {{ range $product, $flags := $products}} {{ $flagCount := 0 }} {{ range $flag := $flags }} {{ $flagCount = add $flagCount 1 }} {{ end }} {{ $countDict = merge $countDict (dict $product $flagCount) }} {{ end }} ``` -------------------------------- ### Checking Review App Status in Go Template Source: https://github.com/arqawa/docs-gitlab-com/blob/main/themes/gitlab-docs/layouts/partials/functions/is-review-app.html This snippet checks if the current page is served from a GitLab review app. It uses `hasPrefix` with `relURL` to determine if the URL starts with '/review-mr' or '/upstream-review-mr'. It returns 'true' if it's a review app, otherwise 'false'. ```Go Template {{/* Determine if this instance of the site is a review app @return string "true" if this page is served from a review app, "false" if not */}} {{- if or (hasPrefix (relURL "") "/review-mr") (hasPrefix (relURL "") "/upstream-review-mr") -}} {{- "true" -}} {{- else -}} {{- "false" -}} {{- end -}} ``` -------------------------------- ### Building and Running Docker Image for GitLab Docs (Shell) Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/releases.md This snippet demonstrates how to build a Docker image for a specific GitLab documentation version and run it locally, mapping port 4000 for access. It's used for testing documentation builds before publication. ```shell docker build -t docs:16.6 -f 16.6.Dockerfile . --build-arg VER=16.6 docker run -it --rm -p 4000:4000 docs:16.6 ``` -------------------------------- ### Checking mise Activation Status Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/setup.md This command checks if `mise` activation was successful in the shell. It's a diagnostic tool to verify `mise` is correctly configured and running. ```shell mise doctor ``` -------------------------------- ### Ignoring OneTrust Images with MutationObserver - JavaScript Source: https://github.com/arqawa/docs-gitlab-com/blob/main/themes/gitlab-docs/layouts/partials/analytics-oneTrust.html This JavaScript code utilizes a MutationObserver to detect dynamically added 'IMG' elements in the DOM. It then iterates through all images that do not have an 'src' attribute starting with 'http' and are not already marked with 'data-ot-ignore', setting the 'data-ot-ignore' attribute to prevent OneTrust from processing them. ```javascript const callback = (mutationsList, observer) => { for (const mutation of mutationsList) { if (mutation.type === 'childList') { mutation.addedNodes.forEach((node) => { if (node.nodeName === 'IMG') { document.querySelectorAll('img:not(\[src^="http"\]):not(\[data-ot-ignore\])').forEach((image) => { image.setAttribute('data-ot-ignore', ''); }); } }); } } }; const config = { attributes: true, childList: true, subtree: true, attributeFilter: ['src'] }; const observer = new MutationObserver(callback); observer.observe(document.documentElement, config); ``` -------------------------------- ### Initializing GitLab Product Analytics SDK in JavaScript Source: https://github.com/arqawa/docs-gitlab-com/blob/main/themes/gitlab-docs/layouts/partials/analytics.html This JavaScript code initializes the GitLab Product Analytics SDK. It configures the SDK with an application ID, host, and cookie consent status, then initializes the client and tracks a page view if all configuration values are present. ```JavaScript const GL_PRODUCT_ANALYTICS_JSON = { appId: '{{ getenv "GITLAB_ANALYTICS_ID" }}', host: '{{ getenv "GITLAB_ANALYTICS_HOST" }}', hasCookieConsent: !0 } // Initialize the SDK if all config is present. if (!Object.values(GL_PRODUCT_ANALYTICS_JSON).includes('')) { window.glClient = window.glSDK.glClientSDK(GL_PRODUCT_ANALYTICS_JSON); window.glClient?.page(); } ``` -------------------------------- ### Initializing Mermaid Diagrams (JavaScript) Source: https://github.com/arqawa/docs-gitlab-com/blob/main/themes/gitlab-docs/layouts/_default/baseof.html This JavaScript snippet initializes the Mermaid diagramming library when the DOM content is fully loaded. It sets `startOnLoad` to true and applies a 'neutral' theme. This initialization is conditional, only occurring if the `hasMermaid` flag is set in the page's store, indicating that Mermaid diagrams are present on the page. ```JavaScript document.addEventListener('DOMContentLoaded', () => { mermaid.initialize({ startOnLoad: true, theme: 'neutral' }); }); ``` -------------------------------- ### Resolving Local Preview Access for Linux Containers Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/setup.md This command sets the `HUGO_BIND_IP` environment variable to `0.0.0.0`. It resolves issues for Linux users building locally in a container who may experience problems accessing the local preview site. ```shell export HUGO_BIND_IP=0.0.0.0 ``` -------------------------------- ### Executing Go Release Archive Script via Make (Go) Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/releases.md This snippet shows the underlying Go command that the `make create-archive-branch` target executes. It runs the `release-archive` command from the `cmd/main.go` script, passing a version argument. ```go go run cmd/main.go release-archive $(VERSION) ``` -------------------------------- ### Generating GitLab Source/IDE Links (Go Template) Source: https://github.com/arqawa/docs-gitlab-com/blob/main/themes/gitlab-docs/layouts/partials/edit-link.html This Go template snippet dynamically constructs URLs for editing documentation files on GitLab. It checks the current file's context, retrieves project details from site data, and formats a URL for either viewing the source blob or opening the file in the Web IDE. It handles different section paths and ensures the correct base URL and file path are used. ```Go Template {{ if .Context.File }} {{ if .Context.File.Section }} {{ $section := partial "functions/page-source-project" .Context }} {{ $productData := index .Context.Site.Data.products "products" }} {{ $sectionData := index $productData (string $section) }} {{ if $sectionData }} {{ $page_path := .Context.File.Path }} {{ if ne $section "gitlab" }} {{ $page_path = strings.TrimLeft "/" (replace $page_path $section "" 1) }} {{ end }} {{ $edit_base_url := "" }} {{ $project := replace (replace $sectionData.repo "https://gitlab.com/" "") ".git" "" }} {{ $default_branch := $sectionData.default_branch }} {{ $doc_dir := $sectionData.docs_dir }} {{ if eq .linkType "source" }} {{ $edit_base_url = printf "https://gitlab.com/%s/-/blob/%s/%s" $project $default_branch $doc_dir }} {{ else if eq .linkType "ide" }} {{ $edit_base_url = printf "https://gitlab.com/-/ide/project/%s/edit/%s/-/%s" $project $default_branch $doc_dir }} {{ end }} [{{ .editText }}]({{ $edit_base_url }}/{{ $page_path }}) {{ end }} {{ end }} {{ end }} ``` -------------------------------- ### Implementing Conditional Page Redirects in Hugo Source: https://github.com/arqawa/docs-gitlab-com/blob/main/themes/gitlab-docs/layouts/partials/redirect.html This Hugo template snippet retrieves the 'redirect_to' parameter from the page's front matter. It then checks if a redirect is specified. If the redirect path starts with 'http', it's treated as an external link. Otherwise, it's considered an internal path; the '.md' extension is removed, and `relref` is used to validate the internal reference. An invalid internal path triggers a warning message. ```Go Template {{ $redirectTo := .Params.redirect\_to }} {{ if $redirectTo }} {{ if hasPrefix $redirectTo "http" }} {{ else }} {{ $redirectPath := replace $redirectTo ".md" "" }} {{ with relref . $redirectPath }} {{ else }} {{ warnf "Invalid internal redirect path in %s: %s" .Page.File $redirectTo }} {{ end }} {{ end }} {{ end }} ``` -------------------------------- ### Combining Availability Details and Version History - Plaintext Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/shortcodes.md Demonstrates how to combine the `details` and `history` shortcodes to provide comprehensive information about feature availability and its version lifecycle. This allows for a complete overview of a feature's status and evolution. ```plaintext {{< details >}} - Tier: some tiers - Offering: some offerings - Status: Experiment - Hotdogs: Yes {{< /details >}} {{< history >}} - Introduced in xyz - Deprecated in abc {{< /history >}} ``` -------------------------------- ### Running All Tests Locally - Shell Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/testing.md This command executes all configured tests for the GitLab Docs site. It leverages the `make` utility to trigger the comprehensive test suite defined in the project's Makefile, ensuring all code and content quality checks are performed before changes are pushed. ```shell make test ``` -------------------------------- ### Executing `create-stable-branch` Make Target (Shell) Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/releases.md This snippet shows the underlying Go command executed by the `make create-stable-branch` target. This command is responsible for initiating the stable branch creation process for a specified GitLab version. ```shell go run cmd/main.go release $(VERSION) ``` -------------------------------- ### Running Specific Go Tests Locally - Shell Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/testing.md This command runs only the Go-specific unit tests for the GitLab Docs site. It uses the `make` utility to target the `go-tests` rule, allowing developers to focus on Go code quality without running the entire test suite, which can save time during development. ```shell make go-tests ``` -------------------------------- ### Generating Dynamic Links and Styling in Go Template Source: https://github.com/arqawa/docs-gitlab-com/blob/main/themes/gitlab-docs/layouts/partials/landing-page/circle-refs.html This Go template snippet initializes styling variables and conditionally updates them based on input parameters like `extra_styling` and `second_row`. It aims to dynamically set CSS classes for column layout. The snippet also includes an incomplete attempt to construct a Markdown link using user data, translation functions, and relative URLs. ```Go Template {{/* Creates the circle links in Reference Architecture section of the homepage. */}} {{ $more_styling := ""}} {{ if .extra_styling }} {{ $more_styling = .extra_styling }} {{ end }} {{ $col_md := "col-md-3"}} {{ if .second_row }} {{ $col_md = "col-md-4" }} {{ end }}* [{{ .total_users}} {{ T "ref-architectures.users" }} ![]({{ )]({{ relURL ) ``` -------------------------------- ### Illustrating GitLab Docs Content Flow with Mermaid Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/architecture.md This Mermaid diagram visualizes the architecture of the GitLab documentation site, showing how content from various GitLab product repositories (e.g., `gitlab-org/gitlab/doc`, `gitlab-org/gitlab-runner/docs`) flows into the `gitlab-org/technical-writing/docs-gitlab-com` project. It then depicts the build pipeline transforming this content into the published `docs.gitlab.com` website, with different paths for specific product documentation. ```Mermaid graph LR A[gitlab-org/gitlab/doc] B[gitlab-org/gitlab-runner/docs] C[gitlab-org/omnibus-gitlab/doc] D[gitlab-org/charts/gitlab/doc] E[gitlab-org/cloud-native/gitlab-operator/doc] Y[gitlab-org/technical-writing/docs-gitlab-com] A --> Y B --> Y C --> Y D --> Y E --> Y Y -- Build pipeline --> Z Z[docs.gitlab.com] M[///] N[//runner/] O[//omnibus/] P[//charts/] Q[//operator/] Z --> M Z --> N Z --> O Z --> P Z --> Q ``` -------------------------------- ### Creating a Warning Alert Box - Plaintext Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/shortcodes.md Shows how to use the `alert` shortcode with `type="warning"` to highlight important warnings or cautions within the documentation. This type of alert is typically used for critical information that users should be aware of. ```plaintext {{< alert type="warning" >}} This is a warning! {{< /alert >}} ``` -------------------------------- ### Initializing Google Tag Manager (GTM) in JavaScript Source: https://github.com/arqawa/docs-gitlab-com/blob/main/themes/gitlab-docs/layouts/partials/analytics.html This snippet initializes Google Tag Manager by asynchronously loading the GTM script and pushing initial data to the 'dataLayer'. It is used for tracking website activity and managing various marketing tags. ```JavaScript (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-NJXWQL'); ``` -------------------------------- ### Executing `create-release-merge-request` Make Target (Shell) Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/releases.md This snippet illustrates the Go command executed by the `make create-release-merge-request` target. This command automates the creation of a merge request for a new release, handling various updates and configurations. ```shell go run cmd/main.go releaseMR $(VERSION) ``` -------------------------------- ### Displaying Availability Details - Plaintext Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/shortcodes.md Shows how to use the `details` shortcode to present structured availability information, such as tiers, offerings, and status, in a collapsible section. This allows for detailed information to be hidden until expanded by the user. ```plaintext {{< details >}} - Tier: Premium, Ultimate with [GitLab Duo Pro](https://docs.gitlab.com/subscriptions/subscription-add-ons/) - Offering: GitLab.com, GitLab Self-Managed, GitLab Dedicated - Status: Experiment - Hotdogs: Yes - Some other thing: Absolutely not {{< /details >}} ``` -------------------------------- ### Running Local Site with Older GitLab Content (Shell) Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/versions.md These commands allow you to run a local GitLab Docs site using older content from a specific GitLab product version (e.g., 16.11). It involves fetching and checking out the corresponding stable branch of the `gitlab` project and then building the docs site with the CI_COMMIT_REF_NAME set to that version, simulating an older content environment. ```shell git -C ../gitlab fetch origin 16-11-stable-ee git -C ../gitlab checkout 16-11-stable-ee CI_COMMIT_REF_NAME=16.11 make view-archive ``` -------------------------------- ### Processing Content with Go Template Source: https://github.com/arqawa/docs-gitlab-com/blob/main/themes/gitlab-docs/layouts/shortcodes/details.html This Go template snippet takes the inner content, splits it by newlines, and iterates through each line. It cleans leading hyphens and spaces, then checks if the line contains a colon to determine if it's a key-value pair or a simple line. Both are rendered using `$.Page.RenderString`. ```Go Template {{- $content := .Inner -}}\n\n{{- $lines := split $content "\\n" -}} {{- range $lines -}} {{- $cleanedLine := replaceRE "^- " "" (trim . " ") -}} {{- if $cleanedLine -}} {{- $parts := split $cleanedLine ":" -}} {{- if ge (len $parts) 2 -}} {{- $key := index $parts 0 -}} {{- $value := delimit (after 1 $parts) ":" -}}* {{- $key | markdownify -}}: {{ $value | $.Page.RenderString -}}\n{{- else -}}* {{- $cleanedLine | $.Page.RenderString -}}\n{{- end -}} {{- end -}} {{- end -}} ``` -------------------------------- ### Creating a Feature Flag Alert Box - Plaintext Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/shortcodes.md Demonstrates the `alert` shortcode with `type="flag"` for indicating content related to feature flags. This helps users identify features that might be conditionally available or under development. ```plaintext {{< alert type="flag" >}} This is a feature flag. {{< /alert >}} ``` -------------------------------- ### Running Local Site with Archive-Style Path (Shell) Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/versions.md This command configures a local GitLab Docs site to behave like an archive site by setting the CI_COMMIT_REF_NAME environment variable to a specific version (e.g., 16.11) before running the make view-archive command. This simulates the URL structure and behavior of an archived version locally. ```shell CI_COMMIT_REF_NAME=16.11 make view-archive ``` -------------------------------- ### Rendering Web IDE Edit Link - Go Template Source: https://github.com/arqawa/docs-gitlab-com/blob/main/themes/gitlab-docs/layouts/partials/footer.html This Go template snippet calls the `edit-link.html` partial to generate a link for editing the current page directly within a Web IDE. It passes a dictionary of parameters including the current page `Context`, a translated edit text (`footer.editWebIDE`), and specifies the `linkType` as 'ide' to trigger the Web IDE functionality. ```Go Template {{ partial "edit-link.html" (dict "Context" . "editText" (T "footer.editWebIDE") "linkType" "ide") }} ``` -------------------------------- ### Determining Source Project in Go Template Source: https://github.com/arqawa/docs-gitlab-com/blob/main/themes/gitlab-docs/layouts/partials/functions/page-source-project.html This snippet checks for the existence of a file and its section. It then attempts to retrieve product data from `$.Site.Data.products` using the file's section as a key. If the specific section data is not found, it defaults the `$section` variable to 'gitlab' before printing the final determined section name. This ensures a valid project name is always returned. ```Go Template {{- if $.File -}} {{- if $.File.Section -}} {{- $section := $.File.Section -}} {{- $productData := index $.Site.Data.products "products" -}} {{- $sectionData := index $productData $section -}} {{- if not $sectionData -}} {{- $section = "gitlab" -}} {{- end -}} {{- print $section -}} {{- end -}} {{- end -}} ``` -------------------------------- ### Listing Running Docker Containers (Shell) Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/releases.md This command is used to list all currently running Docker containers, which helps in identifying a container's ID before performing actions like stopping it. ```shell docker container ls ``` -------------------------------- ### Creating a Note Alert Box - Plaintext Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/shortcodes.md Illustrates the usage of the `alert` shortcode with `type="note"` to display informational messages. Standard Markdown content, including lists, can be included within the alert box for rich formatting. ```plaintext {{< alert type="note" >}} Here's some note text. You can add any standard markdown inside any of these alerts. For example, here's a list: - One - Two - Five hundred {{< /alert >}} ``` -------------------------------- ### Conditional Robots.txt Generation with Go Template Source: https://github.com/arqawa/docs-gitlab-com/blob/main/themes/gitlab-docs/layouts/robots.txt This Go template logic conditionally generates the `robots.txt` content. If the site is identified as a pre-release version and hosted on `docs.gitlab.com`, it outputs specific disallow rules. Otherwise, it indicates that the file is not read by crawlers, directing to the domain root's `robots.txt`. ```Go Template {{- $isPreRelease := partial "functions/is-pre-release-version.html" . -}}\n{{- if and (eq $isPreRelease "true") (hasPrefix .Site.BaseURL "https://docs.gitlab.com") -}}\nUser-agent: *\n# Block crawlers from review apps\nDisallow: /review-mr\nDisallow: /upstream-review-mr\n# Block crawlers from released versions\nDisallow: /1\nDisallow: /2\nDisallow: /3\nSitemap: https://docs.gitlab.com/sitemap.xml\n{{- else -}}\n{{/* Review app or released version. */}}\nThis file is not read by crawlers.\nSee robots.txt at the domain root for active crawler rules.\n\n{{- end -}} ``` -------------------------------- ### Creating Archive Branch with Automatic Version Resolution (Make) Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/releases.md This Make command is used to create an archive branch for documentation releases, allowing the system to automatically resolve the correct version without explicit specification. ```shell make create-archive-branch ``` -------------------------------- ### Exposing Walkthrough Data to Global JavaScript Source: https://github.com/arqawa/docs-gitlab-com/blob/main/themes/gitlab-docs/layouts/shortcodes/walkthrough.html This snippet makes the processed walkthrough data available globally in the browser's `window.walkthroughData` object. It uses a logical OR assignment (`||`) to initialize the object if it doesn't exist and then assigns the JSON-stringified walkthrough data, dynamically generated by Go Template, to a property named after the walkthrough filename. It also sets a page store variable `hasWalkthrough` to true. ```JavaScript // Store workflow content as a global variable for use in the FeatureWalkthrough Vue component window.walkthroughData = window.walkthroughData || {}; window.walkthroughData["{{ $walkthroughFilename }}"] = {{ $walkthroughData | jsonify | safeJS }}; {{ .Page.Store.Set "hasWalkthrough" true }} {{ $fallback := .Inner }} ``` -------------------------------- ### Embedding a Walkthrough using Hugo Shortcode Source: https://github.com/arqawa/docs-gitlab-com/blob/main/doc/experiments.md This snippet demonstrates how to embed a pre-defined walkthrough into a markdown page using a Hugo shortcode. The `data` attribute specifies the YAML file (without extension) containing the walkthrough's content. The markdown content between the shortcode tags serves as fallback for environments where shortcodes cannot be rendered, such as `/help`. ```plaintext {{}} Some text here. Here's a list: - One - Two - Five hundred {{}} ``` -------------------------------- ### Generating Link List from Content in Hugo Template Source: https://github.com/arqawa/docs-gitlab-com/blob/main/themes/gitlab-docs/layouts/shortcodes/cards.html This Go Template snippet iterates through lines of content, identifies markdown-style links, and constructs a list of dictionaries. It resolves internal links to their Hugo page details (description, permalink) and handles external links directly. The resulting list is then used to render the links. ```Go Template {{ $content := .Inner }} {{ $lines := split $content "\\n" }} {{ $linkPattern := "\\\\[(\[^\\\\]\]+)\\\\]\\\\((\[^\\\\)\]+)\\\\)" }} {{ $items := slice }} {{ range $lines }} {{ if hasPrefix (trim . " ") "-" }} {{ $cleanLine := trim (strings.TrimPrefix "-" (trim . " ")) " " }} {{ if findRE $linkPattern $cleanLine }} {{ $title := replaceRE $linkPattern "$1" $cleanLine }} {{ $rawLink := replaceRE $linkPattern "$2" $cleanLine }} {{ $isExternal := or (hasPrefix $rawLink "http") (hasPrefix $rawLink "https") }} {{ $href := $rawLink }} {{ $description := "" }} {{ if not $isExternal }} {{ $relDir := path.Dir $.Page.File.Path }} {{ $targetPath := path.Clean (path.Join $relDir $rawLink) | replaceRE "\\\\.md$" "" }} {{ if $page := $.Site.GetPage $targetPath }} {{ $description = $page.Description }} {{ $href = $page.RelPermalink }} {{ end }} {{ end }} {{ $items = $items | append (dict "title" $title "href" $href "description" $description) }} {{ end }} {{ end }} {{ end }} {{ range $items }}[{{ .title }} {{ if ne .description "" }} {{ .description }} {{ end }}]({{ .href }}) {{ end }} ``` -------------------------------- ### Configuring GitLab API Endpoints in Go Template Source: https://github.com/arqawa/docs-gitlab-com/blob/main/themes/gitlab-docs/layouts/shortcodes/archiveList.html This snippet initializes variables for Hugo's launch version and defines a dictionary of GitLab API endpoints. Each endpoint includes a URL for fetching registry tags and a version filter specifying criteria (e.g., 'newer-or-equal', 'newer', 'older') for version selection. It also sets up the order for processing these endpoints and initializes error and response tracking variables. ```Go Template {{ $hugoLaunchVersion := float site.Params.hugoLaunchVersion }} {{ $endpoints := dict "v3" (dict "url" "https://gitlab.com/api/v4/projects/51970333/registry/repositories/8244403/tags?per_page=100" "versionFilter" (dict "type" "newer-or-equal" "version" $hugoLaunchVersion )) "v2" (dict "url" "https://gitlab.com/api/v4/projects/1794617/registry/repositories/3631228/tags?per_page=100" "versionFilter" (dict "type" "newer" "majorVersion" 15 "minorVersion" 6 )) "v1" (dict "url" "https://gitlab.com/api/v4/projects/1794617/registry/repositories/631635/tags?per_page=100" "versionFilter" (dict "type" "older" "majorVersion" 15 "minorVersion" 6 )) }} {{ $endpointOrder := slice "v3" "v2" "v1" }} {{ $hasError := false }} {{ $responses := dict }} ``` -------------------------------- ### Rendering Page Source Edit Link - Go Template Source: https://github.com/arqawa/docs-gitlab-com/blob/main/themes/gitlab-docs/layouts/partials/footer.html This Go template snippet calls the `edit-link.html` partial to generate a link for viewing the current page's source code. It passes a dictionary of parameters including the current page `Context`, a translated edit text (`footer.viewPageSrc`), and specifies the `linkType` as 'source' to indicate its purpose. ```Go Template {{ partial "edit-link.html" (dict "Context" . "editText" (T "footer.viewPageSrc") "linkType" "source") }} ``` -------------------------------- ### Generating Dynamic Landing Page Structure with Hugo Templates Source: https://github.com/arqawa/docs-gitlab-com/blob/main/themes/gitlab-docs/layouts/partials/landing-page/site-sections.html This comprehensive Hugo template iterates through site data to construct a dynamic landing page. It creates tabbed sections, populating them with content from other pages, and also renders secondary sections with lists of links. It uses range, if, printf, index, partial, and GetPage functions to achieve this. ```Go Template {{ $data := index .Site.Data .Site.Language.Lang "landing" }} {{ $primarySection := $data.sectionTabs }} {{ $tabTitles := "" }} {{ range $index, $element := $primarySection}} {{ if $index }} {{ $tabTitles = printf "%s,%s" $tabTitles $element.title }} {{ else }} {{ $tabTitles = $element.title }} {{ end }} {{ end }} {{ $tabContentsStr := "" }} {{ $openUL := "\n
    \n" }} {{ $closeUL := "\n
\n"}} {{ range $index, $element := $primarySection }} {{ $refs := $element.refs }} {{ $tabContents := "" }} {{ range $refs }} {{ $page := $.Site.GetPage . }} {{ if $page }} {{ $tabContents = printf "%s%s" $tabContents (partial "landing-page/tabContent.html" (dict "title" $page.Title "url" $page.RelPermalink "description" $page.Description)) }} {{ end }} {{ end }} {{ $srHeading := printf "\n

%s

\n" $element.title }} {{ $tabContents = printf "%s%s%s%s" $srHeading $openUL $tabContents $closeUL }} {{ if $index }} {{ $tabContentsStr = printf "%s,%s" $tabContentsStr $tabContents }} {{ else }} {{ $tabContentsStr = $tabContents }} {{ end }} {{ end }} {{ $secondarySection := $data.secondarySections }} {{ range $secondarySection }} ### {{ .title }} {{ $links := .links }} {{ range $links }} {{ if .type }}* [{{.title }}]({{) {{ else }}* [{{.title }}]({{) {{ end }} {{ end }} {{ end }} ``` -------------------------------- ### Initializing Elastic Search Constants in JavaScript Source: https://github.com/arqawa/docs-gitlab-com/blob/main/themes/gitlab-docs/layouts/partials/head.html This snippet initializes JavaScript constants for Elastic Search configuration, retrieving values from environment variables. These constants are crucial for connecting to and utilizing an Elastic Search backend for site search functionality. ```JavaScript const ELASTIC_CLOUD_ID = '{{ getenv "ELASTIC_CLOUD_ID" }}'; const ELASTIC_KEY = '{{ getenv "ELASTIC_KEY" }}'; const ELASTIC_INDEX = '{{ getenv "ELASTIC_INDEX" }}'; ``` -------------------------------- ### Defining Main Template with Search Backend Logic - Go Template Source: https://github.com/arqawa/docs-gitlab-com/blob/main/themes/gitlab-docs/layouts/_default/search-results.html This Go template snippet defines the 'main' block, which is the primary content area of a web page. It conditionally renders a 'Search Latest Docs' heading based on the 'SEARCH_BACKEND' environment variable being 'elastic' or empty. It also includes a 'footer.html' partial. ```Go Template {{ define "main" }} {{ if or (eq (getenv "SEARCH_BACKEND") "elastic") (eq (getenv "SEARCH_BACKEND") "") }} {{ T "searchResults.searchLatestDocs" }} ======================================== {{ else }} {{ end }} {{ partial "footer.html" . }} {{ if or (eq (getenv "SEARCH_BACKEND") "elastic") (eq (getenv "SEARCH_BACKEND") "") }} {{ else }} {{ end }} {{ end }} ```