mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-05-16 05:47:35 +08:00
Move PX4 Guide source into /docs (#24490)
* Add vitepress tree * Update existing workflows so they dont trigger on changes in the docs path * Add nojekyll, package.json, LICENCE etc * Add crowdin docs upload/download scripts * Add docs flaw checker workflows * Used docs prefix for docs workflows * Crowdin obvious fixes * ci: docs move to self hosted runner runs on a beefy server for faster builds Signed-off-by: Ramon Roche <mrpollo@gmail.com> * ci: don't run build action for docs or ci changes Signed-off-by: Ramon Roche <mrpollo@gmail.com> * ci: update runners Signed-off-by: Ramon Roche <mrpollo@gmail.com> * Add docs/en * Add docs assets and scripts * Fix up editlinks to point to PX4 sources * Download just the translations that are supported * Add translation sources for zh, uk, ko * Update latest tranlsation and uorb graphs * update vitepress to latest --------- Signed-off-by: Ramon Roche <mrpollo@gmail.com> Co-authored-by: Ramon Roche <mrpollo@gmail.com>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
#! /usr/bin/python
|
||||
|
||||
"""
|
||||
Generates a file _sidebar.md for each SUMMARY.md in the immediate folders (e.g. /en/SUMMARY.md)
|
||||
This is stored in github. Can be called at build time to create/deploy for docsify builds.
|
||||
Note, we don't "support" docsify - this is experimental
|
||||
"""
|
||||
import os
|
||||
import re
|
||||
|
||||
|
||||
def modify_summary_links(directory):
|
||||
# Iterate over all immediate subdirectories
|
||||
for subdir in next(os.walk(directory))[1]:
|
||||
summary_md_path = os.path.join(directory, subdir, 'SUMMARY.md')
|
||||
# Check if SUMMARY.md exists in the subdirectory
|
||||
if os.path.isfile(summary_md_path):
|
||||
# print(f"Processing: {summary_md_path}")
|
||||
# Read the SUMMARY.md content
|
||||
with open(summary_md_path, 'r', encoding='utf-8') as f:
|
||||
summary_content = f.read()
|
||||
|
||||
# Modify the URLs to start with '/'
|
||||
modified_content = re.sub(r'\]\((?!/)', '](/', summary_content)
|
||||
|
||||
# Add generated disclaimer
|
||||
disclaimer = "<!-- GENERATED CONTENT: DO NOT EDIT -->\n"
|
||||
modified_content = disclaimer + modified_content
|
||||
# Create the output file path
|
||||
output_path = os.path.join(directory, subdir, '_sidebar.md')
|
||||
|
||||
# Write the modified content to the output file
|
||||
with open(output_path, 'w', encoding='utf-8') as f:
|
||||
f.write(modified_content)
|
||||
|
||||
# print(f"Modified SUMMARY.md saved as {output_path}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Specify the directory to search for SUMMARY.md files
|
||||
specified_directory = "."
|
||||
|
||||
# Call the function to modify SUMMARY.md links in all subdirectories
|
||||
modify_summary_links(specified_directory)
|
||||
@@ -0,0 +1,132 @@
|
||||
#! /usr/bin/python
|
||||
|
||||
"""
|
||||
|
||||
"""
|
||||
|
||||
#import lxml.etree as ET
|
||||
#import requests
|
||||
#from bs4 import BeautifulSoup as bs
|
||||
import re
|
||||
import os # for walk, evironment vars
|
||||
import subprocess #so I can use git to get the modified dates.
|
||||
import argparse
|
||||
|
||||
dir_name='.'
|
||||
#git log -1 --format="%as" -- .\zh\uavcan\notes.md
|
||||
|
||||
include_dirs = set(['en','zh','ko','uk']) #update for new language builds.
|
||||
exclude_dirs = set(['.vitepress','node_modules']) #update for new language builds.
|
||||
|
||||
my_parser = argparse.ArgumentParser(description='Generate sitemap for all markdown files in directory (default to main for output)')
|
||||
# Add the arguments
|
||||
my_parser.add_argument('-v',
|
||||
'--version',
|
||||
action='store',
|
||||
type=str,
|
||||
#nargs=1,
|
||||
default='main')
|
||||
my_parser.add_argument('-d',
|
||||
'--date',
|
||||
action='store_true',
|
||||
help='generate date information')
|
||||
my_parser.add_argument('-o',
|
||||
'--output',
|
||||
action='store',
|
||||
type=str,
|
||||
#nargs=1,
|
||||
default='./.vitepress/dist/')
|
||||
|
||||
# Execute the parse_args() method
|
||||
args = my_parser.parse_args()
|
||||
build_version = args.version
|
||||
|
||||
#Get build version from process env by preference.
|
||||
BRANCH_NAME = os.getenv('BRANCH_NAME')
|
||||
if BRANCH_NAME:
|
||||
build_version=BRANCH_NAME
|
||||
|
||||
url_prefix = 'https://docs.px4.io/%s' % build_version
|
||||
|
||||
sitemapitems=[]
|
||||
|
||||
for subdir, dirs, files in os.walk(dir_name, topdown=True):
|
||||
|
||||
if subdir == '.':
|
||||
#print("RootFile: %s" % originalfile)
|
||||
#Handle a root file.
|
||||
continue
|
||||
|
||||
# Check if any of the include directories is in the subdir path
|
||||
if any(f"/{inc_dir}/" in subdir or f"\\{inc_dir}\\" in subdir for inc_dir in include_dirs):
|
||||
pass
|
||||
#print(f"SUBDIR: {subdir}")
|
||||
else:
|
||||
continue
|
||||
|
||||
if any(f"/{ex_dir}/" in subdir or f"\\{ex_dir}\\" in subdir for ex_dir in exclude_dirs):
|
||||
continue
|
||||
#print(f"SUBDIR Ex: {subdir}")
|
||||
|
||||
|
||||
for file in files:
|
||||
#print(f"xxDebug: {file}")
|
||||
sitemapitem = dict()
|
||||
sitemapitem['changefreq']='daily'
|
||||
if not file.endswith('.md'): #only process md files.
|
||||
#print(f"Skip: {file} (not md)")
|
||||
continue
|
||||
|
||||
originalfile=subdir+'\\'+file
|
||||
dir_name=subdir[2:].replace('\\','/')
|
||||
orig_file_forwardslash=originalfile.replace('\\','/')
|
||||
#git log -1 --format="%as" -- .\zh\uavcan\notes.md
|
||||
if args.date:
|
||||
modified_datestamp = subprocess.run(["git", "log", "-1", '--format="%as"', "--", "%s" % orig_file_forwardslash],capture_output=True).stdout.decode('UTF-8')
|
||||
sitemapitem['modified']=modified_datestamp.strip().strip('"')
|
||||
#print(f"debugXX: {sitemapitem['modified']}")
|
||||
file_name=file[:-3]+'.html'
|
||||
if file_name.startswith('README'):
|
||||
file_name=''
|
||||
if file_name.startswith('index'):
|
||||
file_name=''
|
||||
url=f"{url_prefix}/{dir_name}/{file_name}"
|
||||
sitemapitem['url']=url
|
||||
|
||||
#print("OrigFile: %s" % originalfile)
|
||||
#print("dir_name: %s" % dir_name)
|
||||
#print("Subdir: %s" % subdir )
|
||||
#print("file_name: %s" % file_name)
|
||||
#print(sitemapitem['url'])
|
||||
|
||||
sitemapitems.append(sitemapitem)
|
||||
|
||||
|
||||
# Generate the sitemap from the sitemapitems
|
||||
all_sitemap_item_text = ""
|
||||
for item in sitemapitems:
|
||||
sitemap_item_text=''
|
||||
sitemap_item_text+=' <url>\n'
|
||||
sitemap_item_text+=f" <loc>{item['url']}</loc>\n"
|
||||
sitemap_item_text+=f" <changefreq>{item['changefreq']}</changefreq>\n"
|
||||
if args.date:
|
||||
sitemap_item_text+=f" <lastmod>{item['modified']}</lastmod>\n"
|
||||
sitemap_item_text+=' </url>\n'
|
||||
|
||||
all_sitemap_item_text+=sitemap_item_text
|
||||
|
||||
sitemaptext = '''<?xml version="1.0" encoding="UTF-8"?>
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||
%s</urlset>
|
||||
''' % all_sitemap_item_text
|
||||
|
||||
# Write the sitemap to file
|
||||
outputfile=args.output+'sitemap.xml'
|
||||
with open(outputfile,"w") as f:
|
||||
f.write(sitemaptext)
|
||||
|
||||
print("Sitemap generated to: %s" % outputfile)
|
||||
|
||||
#print("BRANCH_NAME: %s" % BRANCH_NAME)
|
||||
#print("Build version: %s" % build_version)
|
||||
|
||||
Reference in New Issue
Block a user