feat(docs): update ci build script and use README instead of index

This commit is contained in:
Ax333l 2022-11-13 14:05:16 +01:00
parent dcf0413af7
commit 27dd5a5184
6 changed files with 24 additions and 18 deletions

View File

@ -6,17 +6,15 @@ set -e
cd "$(dirname "$0")"
docs_git_repo="${REVANCED_DOCS_REPO:-https://github.com/revanced/revanced-documentation.git}"
export REVANCED_DOCS_FOLDER="_docs_src"
git clone "$docs_git_repo" "$REVANCED_DOCS_FOLDER"
git clone "$docs_git_repo" "_docs_src"
# TODO: transform a tag links so this works properly...
#export REVANCED_DOCS_FOLDER="_docs_src/docs"
# Do this because the docs repo doesn't have any actual docs right now
cd "$REVANCED_DOCS_FOLDER"
cp README.md index.md
cd -
#git clone --recurse-submodules "$docs_git_repo" "_docs_src"
# Copy assets from docs repo to here.
mkdir -p static/docs
cp -r "$REVANCED_DOCS_FOLDER"/assets static/docs/assets || true
# mkdir -p static/docs
# cp -r "$REVANCED_DOCS_FOLDER"/assets static/docs/assets || true
npm run build

View File

@ -58,7 +58,7 @@ if (docs_folder === undefined) {
docs_folder = "testing-docs";
}
const ignored_items = ["assets", "README.md"];
const ignored_items = ["assets"];
/// Utility functions
@ -84,9 +84,9 @@ function get_slug_of_node(node: DocsTreeNode): string {
// Get a document. Returns null if it does not exist.
export function get(slug: string): Document|null {
let target = path.join(docs_folder, slug);
// Handle index file for folder.
// Handle index (readme) file for folder.
if (exists(target) && is_directory(target)) {
target += "/index";
target += "/README";
}
const dir = path.dirname(target);
@ -129,9 +129,9 @@ function process_file(fname: string): DocumentInfo {
.substring(`${docs_folder}/`.length, fname.length - (get_ext(fname).length + 1))
.split("/");
// Remove `index` suffix if present.
const last_index = parts.length - 1;
if (parts[last_index] == "index") {
// Remove `README` suffix if present.
const last_part_index = parts.length - 1;
if (parts[last_part_index] == "README") {
parts.pop();
}
@ -142,7 +142,7 @@ function process_file(fname: string): DocumentInfo {
}
// Returns a document tree.
function process_folder(dir: string): DocsTree {
function process_folder(dir: string): DocsTree|null {
let tree: DocsTree = {
index: null,
nodes: []
@ -168,13 +168,17 @@ function process_folder(dir: string): DocsTree {
}
for (const ext of supported_filetypes) {
if (item == `index.${ext}`) {
if (item == `README.${ext}`) {
is_index_file = true;
}
}
}
const node = is_dir ? process_folder(itemPath) : process_file(itemPath);
if (node === null) {
console.error(`The ${itemPath} directory does not have a README/index file! ignoring...`)
continue;
}
if (is_index_file) {
tree.index = node;
@ -184,7 +188,7 @@ function process_folder(dir: string): DocsTree {
}
if (tree.index === null) {
throw Error(`${dir} has no index file.`);
return null;
}
// `numeric: true` because we want to be able to specify
@ -198,5 +202,9 @@ function process_folder(dir: string): DocsTree {
// Returns the document tree.
export function index_content(): DocsTree {
return process_folder(docs_folder);
const tree = process_folder(docs_folder);
if (tree === null) {
throw new Error("Root must have index (README) file.")
}
return tree;
}