Skip to content

Commit

Permalink
create files
Browse files Browse the repository at this point in the history
  • Loading branch information
Mara-Li committed Dec 24, 2024
1 parent 7bec5fa commit e36f2e1
Show file tree
Hide file tree
Showing 39 changed files with 1,850 additions and 2 deletions.
65 changes: 65 additions & 0 deletions .github/find_unused_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from pathlib import Path
import os
import argparse
from typing import Optional
import yaml


def find_unused_media(img_path: Optional[Path] = None, dry_run: bool = False):
# load mkdocs.yml
with open("mkdocs.yml", "r", encoding="utf-8") as f:
# remove all !! pairs from the yaml file
data = f.read()
data = data.replace("!!", "")
config = yaml.safe_load(data)

docs_dir = Path.cwd() / Path(config.get("docs_dir", "docs"))
assets_dir = Path(docs_dir, config["extra"]["attachments"])
print(f"Looking for unused images in {assets_dir}...")
if img_path:
assets_dir = img_path

images = [
file
for file in assets_dir.rglob("*")
if file.is_file() and file.suffix in [".png", ".jpg", ".jpeg", ".gif", ".svg"]
]
md_files = [file for file in docs_dir.rglob("*.md") if file.is_file()]

# Search for images in markdown files

used_images = []

for md_file in md_files:
for image in images:
with open(md_file, "r", encoding="utf-8") as f:
if image.name in f.read():
used_images.append(image)

# compare the two lists
unused_images = [image for image in images if image not in used_images]

# delete unused images

if unused_images:
print(f"Found {len(unused_images)} unused images in {assets_dir}. Deleting...")
for image in unused_images:
if not dry_run:
print(image)
os.remove(image)
else:
print(f"Would delete {image}")
else:
print(f"Found no unused images in {assets_dir}.")


if __name__ == "__main__":
# use argparse to get the path to the assets folder
parser = argparse.ArgumentParser()
parser.add_argument("--path", type=str, help="Path to the assets folder")
parser.add_argument(
"--dry-run", action="store_true", help="Do not delete unused images"
)
args = parser.parse_args()
path = Path(args.path) if args.path else None
find_unused_media(img_path=path, dry_run=args.dry_run)
55 changes: 55 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Publish

on:
workflow_dispatch:
push:
branches:
- main
paths:
- 'README.md'
- 'overrides/**'
- 'docs/**'
- 'mkdocs.yml'
- 'uv.lock'
repository_dispatch:
types: [build]

permissions:
contents: write
pages: write
id-token: write

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.GH_PAT }}
fetch-depth: 0
submodules: 'recursive'
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
enable-cache: true
cache-dependency-glob: "uv.lock"
- name: "Submodule fetching"
continue-on-error: true
run: |
git submodule update --init --recursive --checkout -f --remote -- "docs"
git config --global user.name "GitHub Action"
git config --global user.email "[email protected]"
git commit -am "chore (update): fetch submodule"
git push
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.13'
cache: "pip"
- name: Install dependencies
run: uv sync
- name: Build
run: |
uv run mkdocs gh-deploy --force
51 changes: 51 additions & 0 deletions .github/workflows/find_unused_images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Repository maintenance
on:
workflow_call:
inputs:
CLEAN:
description: "Clean unused images"
required: false
default: true
type: boolean
DRY_RUN:
description: "Dry run"
required: false
default: false
type: boolean
BRANCH:
type: string
description: 'Branch to push changes to'
required: false
default: 'main'
secrets:
GH_PAT:
required: true
author_email:
required: false
description: "The author email"
author_name:
required: false
description: "The author name"
jobs:
unused_images:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.13
cache: pipenv
- name: Clean
if: inputs.CLEAN
run: |
echo "Cleaning"
pipenv install pyyaml
pipenv run python .github/find_unused_image.py
- name: Commit
if: inputs.CLEAN && inputs.DRY_RUN == false
uses: actions-js/push@master
with:
github_token: ${{ secrets.GH_PAT || secrets.GITHUB_TOKEN}}
author_email: ${{ secrets.AUTHOR_EMAIL || 'github-actions[bot]@users.noreply.github.com' }}
author_name: ${{ secrets.AUTHOR_NAME || 'github-actions[bot]' }}
branch: ${{ inputs.BRANCH }}
134 changes: 134 additions & 0 deletions .github/workflows/generate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
name: Generate website

on:
workflow_dispatch:
inputs:
site_name:
type: string
required: true
description: "The name of the site"
site_url:
type: string
required: true
description: "The url of the site"
site_description:
type: string
required: true
description: "The description of the site"
site_author:
type: string
required: true
description: "The author of the site"
language:
type: string
required: true
description: "The language of the site"
auto_h1:
type: boolean
required: false
description: "Automatically add h1 to pages"
default: false
comments:
type: boolean
required: false
description: "Enable comments"
default: false
auto_merge:
description: "Automatically merge the pull request"
required: false
default: false
type: boolean

permissions:
contents: write
pull-requests: write

jobs:
run:
runs-on: ubuntu-latest
steps:
- name: Print github.event.inputs
run: |
echo "📫 Commands arguments" >> $GITHUB_STEP_SUMMARY
echo "- site_name: ${{ github.event.inputs.site_name }}" >> $GITHUB_STEP_SUMMARY
echo "- site_url: ${{ github.event.inputs.site_url }}" >> $GITHUB_STEP_SUMMARY
echo "- site_description: ${{ github.event.inputs.site_description }}" >> $GITHUB_STEP_SUMMARY
echo "- site_author: ${{ github.event.inputs.site_author }}" >> $GITHUB_STEP_SUMMARY
echo "- language: ${{ github.event.inputs.language }}" >> $GITHUB_STEP_SUMMARY
echo "- auto_h1: ${{ github.event.inputs.auto_h1 }}" >> $GITHUB_STEP_SUMMARY
echo "- comments: ${{ github.event.inputs.comments }}" >> $GITHUB_STEP_SUMMARY
echo "- template_type: ${{ github.event.inputs.template_type }}" >> $GITHUB_STEP_SUMMARY
echo "ACT: ${{ env.ACT }}"
- name: checkout repo
uses: actions/checkout@v4
- name: Install python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
pip install pydantic requests
- name: Format arguments
id: args
run:
|
auto_h1=''
comments=''
if [ "${{ github.event.inputs.auto_h1 }}" = "true" ]; then
auto_h1='--auto-h1'
fi
if [ "${{ github.event.inputs.comments }}" = "true" ]; then
comments='--comments'
fi
echo "auto_h1=$auto_h1" >> $GITHUB_OUTPUT
echo "comments=$comments" >> $GITHUB_OUTPUT
echo "- auto_h1: $auto_h1" >> $GITHUB_STEP_SUMMARY
echo "- comments: $comments" >> $GITHUB_STEP_SUMMARY
- name: Generate files
run: |
echo "📝 Generate files"
pwd
ls *.py
echo "📝 Generate files" >> $GITHUB_STEP_SUMMARY
echo "---" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
python3 generate_template.py "${{github.event.inputs.site_name}}" "${{github.event.inputs.site_url}}" "${{github.event.inputs.site_description}}" "${{github.event.inputs.site_author}}" "${{github.event.inputs.language}}" ${{ steps.args.outputs.auto_h1 }} ${{ steps.args.outputs.comments }} >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
- name: Pull Request
id: cpr
uses: peter-evans/create-pull-request@v5
with:
commit-message: Generating template
title: "First commit -- Generate template"
body: |
📫 Commands arguments
- site_name: ${{ github.event.inputs.site_name }}
- site_url: ${{ github.event.inputs.site_url }}
- site_description: ${{ github.event.inputs.site_description }}
- site_author: ${{ github.event.inputs.site_author }}
- language: ${{ github.event.inputs.language }}
- auto_h1: ${{ github.event.inputs.auto_h1 }}
- comments: ${{ github.event.inputs.comments }}
- Generated by [Create Pull Request](https://github.com/peter-evans/create-pull-request)
labels: |
generate
branch: generate
base: "main"
delete-branch: true
token: ${{ secrets.GH_TOKEN }}
- name: AutoMerging
id: automerge
if: ${{ inputs.AUTO_MERGE }}
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
gh pr merge ${{ steps.cpr.outputs.pull-request-number }} --squash
echo "Pull Request merged"
echo "done=true" >> $GITHUB_OUTPUT
- name: Delete update branch if possible
if: ${{ inputs.AUTO_MERGE && steps.automerge.outputs.done == 'true' }}
run: |
# verify if the branch exists
if [[ $(git ls-remote --heads origin generate | wc -l) -eq 1 ]]; then
git push origin --delete generate
fi
43 changes: 43 additions & 0 deletions .github/workflows/index.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Index Creation

on:
workflow_dispatch:
inputs:
category_name:
type: string
required: true
description: "The new folder name"
path:
type: string
required: false
description: "The path of the new folder. Ex: category/subcategory"
description:
type: string
required: false
description: "The description of the category."
toc_hide:
type: boolean
required: false
description: "Hide the toc in the index file."
nav_hide:
type: boolean
required: false
description: "Hide the navigation menu in the index file."
dry_run:
type: boolean
required: false
description: "Do not create new category index, just log."

jobs:
run:
uses: Enveloppe/actions/.github/workflows/index.yml@main
with:
category_name: ${{ inputs.category_name}}
path: ${{ inputs.path}}
description: ${{ inputs.description}}
toc_hide: ${{ inputs.toc_hide}}
nav_hide: ${{ inputs.nav_hide}}
dry_run: ${{ inputs.dry_run}}
secrets:
GH_PAT: ${{ secrets.GITHUB_TOKEN }}

23 changes: 23 additions & 0 deletions .github/workflows/optimize.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Optimize images
on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:

jobs:
optimize-images:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: optimize
uses: calibreapp/image-actions@main
with:
githubToken: ${{ secrets.GITHUB_TOKEN}}
ignorePaths: "_assets/img/avatar_index.gif,_assets/meta/**"
compressOnly: true
- name: "Commit & push"
uses: actions-js/push@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
message: "[CI] Optimize images"
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# mkdocs
Mkdocs V2 electric bungalow
# Requirements
- Python 3.12 or higher
- [uv](https://docs.astral.sh/uv/)

1 change: 1 addition & 0 deletions docs/_assets/icons/file.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/_assets/icons/folder-open.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/_assets/icons/index.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit e36f2e1

Please sign in to comment.