Skip to content

Commit

Permalink
Fix issue links to functions being resolved, if there are multiple fu…
Browse files Browse the repository at this point in the history
…nction declarations with the same name.
  • Loading branch information
joethei committed Oct 18, 2023
1 parent c9c18ae commit afcde9a
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build-typescript-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ jobs:
cd config
api-extractor run --local --verbose
- name: Pre-Process API Extractor output
run: node pre-process.js

- name: Clone API Documenter fork
run: git clone https://github.com/ericaxu/rushstack-obsidian.git

Expand Down
1 change: 1 addition & 0 deletions config/gendoc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# 1. Run api-extractor
api-extractor run --local --verbose
node pre-process.js

# Remove everything under ../en/Reference/TypeScript API before doing step 2
rm -rf ../en/Reference/TypeScript\ API/*
Expand Down
53 changes: 48 additions & 5 deletions config/post-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@ async function organizeIntoFolders() {

const remainingFiles = await fs.readdir(sourceDir);
for (const file of remainingFiles) {
if (!file.endsWith('.md')) {
continue;
}

const fileName = path.basename(file, '.md');

if (await folderExists(path.join(sourceDir, fileName))) {
Expand All @@ -131,9 +127,56 @@ async function organizeIntoFolders() {
}
}

async function updateFileLinks(folderPath) {
try {
const files = await fs.readdir(folderPath);

for (const file of files) {
if(!file.endsWith('.md')) {
const joined = path.join(sourceDir, file);
if(await folderExists(joined)) {
await updateFileLinks(joined);
}
continue;
}

try {
let filePath = path.join(folderPath, file);
let fileContent = await fs.readFile(filePath, 'utf-8');
const regex = /::(.*)::(.*)::/g;
const matches = fileContent.matchAll(regex);
for(const match of matches) {
let alias = match[2];
if(match[2] === '') {
alias = match[1];
}
let filename = match[1].split('.').pop().toLowerCase();

//prefer specific API class
if(filename === 'getleaf') {
filename = 'workspace.getleaf_1';
}
//remove any backslashes in links.
filename = filename.replace('\\', '');
alias = alias.replace('\\', '');

fileContent = fileContent.replaceAll(regex, `[${alias}](obsidian.${filename}.md)`);
}
await fs.writeFile(filePath, fileContent, 'utf-8');
console.log(`Replaced files: ${filePath}`);
} catch (err) {
console.error(`Error processing file: ${err.message}`);
}
}
} catch (err) {
console.error(`Error reading directory: ${err.message}`);
}
}

async function main() {
await renameFiles(folderPath);;
await renameFiles(folderPath);
await organizeIntoFolders();
await updateFileLinks(folderPath);
}

main();
30 changes: 30 additions & 0 deletions config/pre-process.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const fs = require('fs/promises');

async function renameDuplicateFunctionReferences() {
const configFile = await fs.readFile('./input/obsidian.api.json', 'utf8');
const configuration = JSON.parse(configFile);
await each(configuration.members);
fs.writeFile('./input/obsidian.api.json', JSON.stringify(configuration));
}

async function each(members) {
members.forEach(member => {

if(member.docComment) {
if(member.docComment.includes('getLeaf')) {
const regex = /{@link Workspace.getLeaf(.*)}/g;
member.docComment = member.docComment.replace(regex, "::Workspace.getLeaf::$1::")
}
}

if(member.members) {
each(member.members);
}
})
}

async function main() {
await renameDuplicateFunctionReferences();
}

main();

0 comments on commit afcde9a

Please sign in to comment.