Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
add better position tracking & place explicit source reference links
Browse files Browse the repository at this point in the history
  • Loading branch information
hsjobeki committed Nov 15, 2023
1 parent 29c1343 commit 7aa0d59
Showing 1 changed file with 34 additions and 14 deletions.
48 changes: 34 additions & 14 deletions json-to-md/convert.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ const getAliases = (aliases, path) => {
const name = ps.join(".");
const title = `${name} ${name.endsWith("'") ? "(Prime)" : ""}`.trim();
const label = ps.join(".");
const target = [PREFIX, "reference", subpath.join("/"), title.replaceAll(".", "-")]
const target = [
PREFIX,
"reference",
subpath.join("/"),
title.replaceAll(".", "-"),
]
.filter(Boolean)
.join("/")
.toLowerCase();
Expand All @@ -67,15 +72,16 @@ const getAliases = (aliases, path) => {
*
* @param {typeof data[number]} item
* @param {typeof data} all
* @returns {{docs: string, position: null | {column: number; file: string; line: number;}}}
*/
const getContent = (item, all) => {
const { aliases, path, docs } = item;
const {
attrDocs: { content: attrContent },
lambdaDocs: { content, countApplied },
lambdaDocs,
} = docs;

let final = attrContent;
let final = attrDocs;
if (!attrContent) {
const others = all.filter(
(other) =>
Expand All @@ -86,31 +92,40 @@ const getContent = (item, all) => {
Boolean(item.docs.attrDocs.content)
);
if (aliasItemWithDocs) {
final = aliasItemWithDocs.docs.attrDocs.content;
final = aliasItemWithDocs.docs.attrDocs;
} else {
final = content;
final = lambdaDocs;
}
}
return final;
return {
docs: final.content,
position: final.position,
};
};

data.forEach((item, idx) => {
const { docs, path, aliases } = item;
const { lambdaDocs, attrDocs } = docs;
const { position, isPrimop, countApplied, content } = lambdaDocs;
const {
docs: { lambdaDocs, attrDocs },
path,
aliases,
} = item;

const { isPrimop, countApplied } = lambdaDocs;
const { content: altContent } = attrDocs;

const { docs, position } = getContent(item, data);

const name = path.join(".");

console.log({ name, aliases });
const title = `${name} ${name.endsWith("'") ? "(Prime)" : ""}`.trim();

const aliasList = getAliases(aliases, path);
const aliasContent = `
# Aliases
${aliasList}
`;
# Aliases
${aliasList}
`;

const mdContent = `---
title: ${title}
Expand All @@ -122,7 +137,7 @@ ${isPrimop ? badge : ""}
---
${
getContent(item, data) ||
docs ||
getLink(
getUrl(position, isPrimop || title.startsWith("builtins.")),
"Contribute Now!"
Expand All @@ -131,6 +146,11 @@ ${
${aliasList ? aliasContent : ""}
defined in: ${getLink(
getUrl(position, isPrimop || title.startsWith("builtins.")),
`${position.file}#{}`
)}
`;

const subpath = path.slice(0, -1);
Expand Down

0 comments on commit 7aa0d59

Please sign in to comment.