Skip to content

Commit

Permalink
Refactor generateTypeLinks function (#161)
Browse files Browse the repository at this point in the history
* External Type Links are now properly added from Members of Classes

* Fixed Class Type Links being added to the `classNames` object instead of the `classTypeNames` object
  • Loading branch information
YetAnotherClown authored Nov 16, 2024
1 parent 2b6c7f5 commit ea59e89
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions docusaurus-plugin-moonwave/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ function parseSectionalClassOrder(content, classOrder, filteredContent) {
const listedSidebar = []
classOrder.forEach((element) => {
const namesWithTags = filteredContent
.filter((luaClass) => luaClass.tags ? luaClass.tags.includes(element.tag) : false)
.filter((luaClass) =>
luaClass.tags ? luaClass.tags.includes(element.tag) : false
)
.map((luaClass) => luaClass.name)
const namesIncludedInClasses = element.classes || []

Expand Down Expand Up @@ -211,39 +213,47 @@ function parseApiCategories(luaClass, apiCategories) {

async function generateTypeLinks(nameSet, luaClasses, baseUrl) {
const classNames = {}

// Handle external types before processing nameSet and classTypesNames, so that user created classes overwrite them
const externalTypes = luaClasses
.filter(
(luaClass) =>
luaClass.external_types && luaClass.external_types.length > 0
)
.forEach((luaClass) =>
luaClass.external_types.forEach(
(type) => (classNames[type.name] = type.url)
)
)

nameSet.forEach((name) => (classNames[name] = `${baseUrl}api/${name}`))

const classTypesNames = luaClasses
const classTypesNames = {}
luaClasses
.filter((luaClass) => luaClass.types.length > 0)
.forEach((luaClass) =>
luaClass.types.forEach(
(type) =>
(classNames[
(classTypesNames[
type.name
] = `${baseUrl}api/${luaClass.name}#${type.name}`)
)
)

const externalTypeNames = {}
luaClasses.forEach((luaClass) => {
const entries = [
luaClass,
...luaClass.functions,
...luaClass.properties,
...luaClass.types,
]

entries
.filter(
(entry) => entry.external_types && entry.external_types.length > 0
)
.forEach((entry) => {
entry.external_types.forEach((type) => {
externalTypeNames[type.name] = type.url
})
})
})

const robloxTypes = await generateRobloxTypes()

const typeLinks = {
...robloxTypes, // The Roblox types go first, as they can be overwritten if the user has created their own classes and types with identical names
...externalTypes, // Should take precedence over Roblox types, but not user created classes
...classNames,
...classTypesNames,
...externalTypeNames,
}

return typeLinks
Expand Down

0 comments on commit ea59e89

Please sign in to comment.