Skip to content

Commit

Permalink
Merge pull request #2703 from gofiber/recipes_docs
Browse files Browse the repository at this point in the history
docusaurus preparations
  • Loading branch information
ReneWerner87 authored Nov 26, 2024
2 parents 7830f51 + fdb7c34 commit 5e3c1b1
Show file tree
Hide file tree
Showing 264 changed files with 4,217 additions and 709 deletions.
33 changes: 33 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Contributing Guidelines

Thank you for considering contributing to this project! To ensure a smooth and efficient process, please follow these guidelines.

## Adding a New Example

1. **Create a Directory**: Create a new directory for your example in the root of the repository. Please do not use a "fiber" prefix in the directory name.

2. **Add a `README.md`**: Each example must include a `README.md` file in its directory. This file should contain the following:

- **Docusaurus Metadata**: Add the following metadata at the top of the `README.md` file:
```markdown
---
title: Your Example Title
keywords: [keyword1, keyword2, keyword3]
---
```

- `title`: A short and descriptive title for your example.
- `keywords`: A list of relevant keywords (excluding "fiber").

- **Content**: The `README.md` should provide a detailed explanation of the example, including:
- The idea behind the example.
- The components used in the example.
- Instructions on how to run the example.
- Any other relevant information.

3. **Update the Overview**: After adding your example, run the following command in the root directory to update the overview table of contents:
```bash
make generate
```

By following these guidelines, you help maintain the quality and consistency of the project. Thank you for your contributions!
55 changes: 55 additions & 0 deletions .github/scripts/sync_docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env bash
set -e

# Some env variables
BRANCH="main"
REPO_URL="github.com/gofiber/docs.git"
AUTHOR_EMAIL="github-actions[bot]@users.noreply.github.com"
AUTHOR_USERNAME="github-actions[bot]"
REPO_DIR="recipes"
COMMIT_URL="https://github.com/gofiber/recipes"

# Set commit author
git config --global user.email "${AUTHOR_EMAIL}"
git config --global user.name "${AUTHOR_USERNAME}"

git clone https://${TOKEN}@${REPO_URL} fiber-docs

latest_commit=$(git rev-parse --short HEAD)

# remove all files in the docs directory
rm -rf $ROOT/../fiberDocs/docs/${REPO_DIR}/*

for f in $(find -E . -type f -iregex '.*\.(md|png|jpe?g|gif|bmp|svg|webp)$' -not -path "./(fiberDocs)/*" -not -path "*/vendor/*" -not -path "*/.github/*" -not -path "*/.*"); do
log_output=$(git log --oneline "${BRANCH}" HEAD~1..HEAD --name-status -- "${f}")

if [[ $log_output != "" || ! -f "fiber-docs/docs/${REPO_DIR}/$f" ]]; then
mkdir -p fiber-docs/docs/${REPO_DIR}/$(dirname $f)
cp "${f}" fiber-docs/docs/${REPO_DIR}/$f
fi
done


# Push changes
cd fiber-docs/ || true
git add .

git commit -m "Add docs from ${COMMIT_URL}/commit/${latest_commit}"

MAX_RETRIES=5
DELAY=5
retry=0

while ((retry < MAX_RETRIES))
do
git push https://${TOKEN}@${REPO_URL} && break
retry=$((retry + 1))
git pull --rebase
sleep $DELAY
done

if ((retry == MAX_RETRIES))
then
echo "Failed to push after $MAX_RETRIES attempts. Exiting with 1."
exit 1
fi
25 changes: 25 additions & 0 deletions .github/scripts/sync_local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
set -e

if [ "$#" -eq 1 ]; then
REPO_DIR="$1"
else
REPO_DIR="recipes" # default value
fi

if [[ ! "$REPO_DIR" =~ ^[a-zA-Z0-9_-]+$ ]]; then
echo "Error: REPO_DIR must contain only alphanumeric characters, underscores, and hyphens" >&2
exit 1
fi

# determine root repo directory
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)"

# remove all files in the docs directory
rm -rf $ROOT/../fiberDocs/docs/${REPO_DIR}/*

for f in $(find -E . -type f -iregex '.*\.(md|png|jpe?g|gif|bmp|svg|webp)$' -not -path "./(fiberDocs)/*" -not -path "*/vendor/*" -not -path "*/.github/*" -not -path "*/.*"); do
echo "Copying $f"
mkdir -p $ROOT/../fiberDocs/docs/${REPO_DIR}/$(dirname $f)
cp "${f}" $ROOT/../fiberDocs/docs/${REPO_DIR}/$f
done
34 changes: 34 additions & 0 deletions .github/workflows/sync-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: 'Sync docs'

on:
push:
branches:
- master
- main
paths:
- '**/*.md'

jobs:
sync-docs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 2

- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: '18'

- name: Install JQ
run: sudo apt-get install jq

- name: Sync docs
run: ./.github/scripts/sync_docs.sh
env:
EVENT: ${{ github.event_name }}
TAG_NAME: ${{ github.ref_name }}
TOKEN: ${{ secrets.DOC_SYNC_TOKEN }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Thumbs.db
*.out

# Dependency directories (remove the comment below to include it)
# vendor/
vendor/

# Go workspace file
go.work
Expand Down
Loading

0 comments on commit 5e3c1b1

Please sign in to comment.