Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added workflow for pulling docs from api repo #774

Merged
merged 2 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions .github/workflows/md_mdx_format_adjuster.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
"""
Script to make Markdown files MDX compatible.

This script scans Markdown files and escapes special characters (<, >, {, })
to make them compatible with the MDX standard used in Docusaurus v3.

This script complies with:
1) Pylint
2) Pydocstyle
3) Pycodestyle
4) Flake8
"""
import os
import argparse
import re

def escape_mdx_characters(text):
"""
Escape special characters in a text string for MDX compatibility.
Avoids escaping already escaped characters.

Args:
text: A string containing the text to be processed.

Returns:
A string with special characters (<, >, {, }) escaped, avoiding
double escaping.
"""
# Regular expressions to find unescaped special characters
patterns = {
"<": r"(?<!\\)<",
">": r"(?<!\\)>",
"{": r"(?<!\\){",
"}": r"(?<!\\)}"
}

# Replace unescaped special characters
for char, pattern in patterns.items():
text = re.sub(pattern, f"\\{char}", text)

return text

def process_file(filepath):
"""
Process a single Markdown file for MDX compatibility.

Args:
filepath: The path to the Markdown file to process.

Returns:
None, writes the processed content back to the file only if there are changes.
"""
with open(filepath, 'r', encoding='utf-8') as file:
content = file.read()

# Escape MDX characters
new_content = escape_mdx_characters(content)

# Write the processed content back to the file only if there is a change
if new_content != content:
with open(filepath, 'w', encoding='utf-8') as file:
file.write(new_content)

def main():
"""
Main function to process all Markdown files in a given directory.

Scans for all Markdown files in the specified directory and processes each
one for MDX compatibility.

Args:
None

Returns:
None
"""
parser = argparse.ArgumentParser(description="Make Markdown files MDX compatible.")
parser.add_argument(
"--directory",
type=str,
required=True,
help="Directory containing Markdown files to process."
)

args = parser.parse_args()

# Process each Markdown file in the directory
for root, _, files in os.walk(args.directory):
for file in files:
if file.lower().endswith(".md"):
process_file(os.path.join(root, file))

if __name__ == "__main__":
main()
26 changes: 26 additions & 0 deletions .github/workflows/pull-docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

git clone --depth=1 --branch develop https://github.com/PalisadoesFoundation/talawa-api.git

mkdir -p docs/talawa-api-docs

cd talawa-api

npm install --global typedoc
npm install typedoc-plugin-markdown
npm i --save-dev @types/node
npx typedoc --entryPoints src --out talawa-api-docs --plugin typedoc-plugin-markdown --theme markdown --entryPointStrategy expand

python3 .github/workflows/md_mdx_format_adjuster.py --directory talawa-api-docs

cd ..

cp -r talawa-api/talawa-api-docs/* docs/talawa-api-docs/

rm -rf talawa-api

git add .

git commit -m "Updated talawa api docs"

git push origin develop
24 changes: 24 additions & 0 deletions .github/workflows/pull-latest-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Pull Talawa API Changes

on:
schedule:
- cron: '0 0 * * 0'

jobs:
pull:
runs-on: ubuntu-latest

steps:
- name: Checkout current repository
uses: actions/checkout@v2

- name: Set up Git config
run: |
git config --global user.email "${{ env.email }}"
git config --global user.name "${{ github.actor }}"

- name: Run bash script
run: |
bash .github/workflows/pull-docs.sh
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
1 change: 0 additions & 1 deletion docs/talawa-api-docs/.nojekyll

This file was deleted.

Loading
Loading