-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Indentation changes and fixes, dejankification of sidebar generation,…
… added some jsdoc comments Created a new function that handles non-grouped sidebar configuration in arrays.js rather than crudely hardcode the variable names within the sidebar definition + some indentation fixes + jsdoc syntax for comments in js
- Loading branch information
Showing
3 changed files
with
169 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,5 @@ docs/ | |
|
||
package-lock.json | ||
.editorconfig | ||
.nvmrc | ||
.nvmrc | ||
out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,124 +1,132 @@ | ||
// Sidebar Arrays | ||
const android_FAQ = { | ||
title: 'Android-specific', // Subgroup for Android FAQ | ||
collapsable: true, sidebarDepth: 1, | ||
path: 'android', // Do not add a trailing slash here unless this also has a child nested in it with its own path | ||
children: [ | ||
'PARSINGERROR', // "Error while parsing the package" error fix. | ||
'REFUSALOFINSTALL', // "App not installed" error fix (very uncommon). | ||
'CANTFINDLOG', // Can't find the log file (non-root). | ||
'CANTFINDMINECRAFT', // Can't find .minecraft (non-root). | ||
'ZINKNOTWORKING', // Zink doesn't work. | ||
'MODCRASHING', // Installing any mod results in a crash. | ||
'MODNOTSHOWINGUP', // My mods don't show up in-game. | ||
'JAVARUNTIMES', // Installing Java runtimes manually. | ||
'JARCRASHED', // Crash when executing a jar. | ||
'32BIT', // Platform and performance limitations (32bit). | ||
'FFMPEG', // Setting up FFMPEG, for Replay Mod. | ||
'SHADERS', // Look what we got here. | ||
'RENDERERS', // I have no idea what they do and why PojavLauncher needs it. | ||
] | ||
} | ||
title: "Android-specific", // Subgroup for Android FAQ | ||
collapsable: true, | ||
sidebarDepth: 1, | ||
path: "android", // Do not add a trailing slash here unless this also has a child nested in it with its own path | ||
children: [ | ||
"PARSINGERROR", // "Error while parsing the package" error fix. | ||
"REFUSALOFINSTALL", // "App not installed" error fix (very uncommon). | ||
"CANTFINDLOG", // Can't find the log file (non-root). | ||
"CANTFINDMINECRAFT", // Can't find .minecraft (non-root). | ||
"ZINKNOTWORKING", // Zink doesn't work. | ||
"MODCRASHING", // Installing any mod results in a crash. | ||
"MODNOTSHOWINGUP", // My mods don't show up in-game. | ||
"JAVARUNTIMES", // Installing Java runtimes manually. | ||
"JARCRASHED", // Crash when executing a jar. | ||
"32BIT", // Platform and performance limitations (32bit). | ||
"FFMPEG", // Setting up FFMPEG, for Replay Mod. | ||
"SHADERS", // Look what we got here. | ||
"RENDERERS", // I have no idea what they do and why PojavLauncher needs it. | ||
], | ||
}; | ||
|
||
const ios_FAQ = { | ||
title: 'iOS-specific', // Subgroup for iOS FAQ | ||
collapsable: true, | ||
sidebarDepth: 1, | ||
path: 'ios', // Do not add a trailing slash here unless this also has a child nested in it with its own path | ||
children: [ | ||
'JIT', // iOS and "JIT". | ||
'APPSTORE', // Will PojavLauncher ever come to App Store for iOS? | ||
] | ||
} | ||
title: "iOS-specific", // Subgroup for iOS FAQ | ||
collapsable: true, | ||
sidebarDepth: 1, | ||
path: "ios", // Do not add a trailing slash here unless this also has a child nested in it with its own path | ||
children: [ | ||
"JIT", // iOS and "JIT". | ||
"APPSTORE", // Will PojavLauncher ever come to App Store for iOS? | ||
], | ||
}; | ||
|
||
export const FAQ = { | ||
title: 'FAQ', // Group for FAQ | ||
collapsable: true, | ||
path: '/wiki/faq/', // Trailing slash is required | ||
children: [ | ||
'INSTALLATIONOFMODSRPWORLDS', // Installation of mods, resource packs, worlds in their correct form. | ||
'CRASHES', // Random crashes during gameplay. | ||
'MODCONFLICT', // I have a mod conflict. | ||
'JAVAVERSION', // Which Java version to use? | ||
'CANTLOGIN', // Can't log in. | ||
// FAQ that applies to both platforms ends here | ||
android_FAQ, // Subgroup for Android-specific FAQ. See Above to configure. | ||
ios_FAQ, // Subgroup for iOS-specific FAQ. See Above to configure. | ||
] | ||
} | ||
title: "FAQ", // Group for FAQ | ||
collapsable: true, | ||
path: "/wiki/faq/", // Trailing slash is required | ||
children: [ | ||
"INSTALLATIONOFMODSRPWORLDS", // Installation of mods, resource packs, worlds in their correct form. | ||
"CRASHES", // Random crashes during gameplay. | ||
"MODCONFLICT", // I have a mod conflict. | ||
"JAVAVERSION", // Which Java version to use? | ||
"CANTLOGIN", // Can't log in. | ||
// FAQ that applies to both platforms ends here | ||
android_FAQ, // Subgroup for Android-specific FAQ. See Above to configure. | ||
ios_FAQ, // Subgroup for iOS-specific FAQ. See Above to configure. | ||
], | ||
}; | ||
|
||
export const Getting_Started = { | ||
title: 'Getting Started', | ||
path: '/wiki/getting_started/', | ||
collapsable: true, | ||
children: [ | ||
'INSTALL', // Installing PojavLauncher. | ||
'BUILD-FROM-SOURCE', // Building PojavLauncher from source. | ||
'SIGN-IN', // Signing in. | ||
'INSTALL-MC', // Downloading Minecraft. | ||
'CUSTOM-CONTROLS', // Customizing the on-screen controls. | ||
'SOCIALMEDIA', // Official PojavLauncher social medias. | ||
], | ||
} | ||
title: "Getting Started", | ||
path: "/wiki/getting_started/", | ||
collapsable: true, | ||
children: [ | ||
"INSTALL", // Installing PojavLauncher. | ||
"BUILD-FROM-SOURCE", // Building PojavLauncher from source. | ||
"SIGN-IN", // Signing in. | ||
"INSTALL-MC", // Downloading Minecraft. | ||
"CUSTOM-CONTROLS", // Customizing the on-screen controls. | ||
"SOCIALMEDIA", // Official PojavLauncher social medias. | ||
], | ||
}; | ||
|
||
export const Going_Further = { | ||
title: 'Going Further', | ||
path: '/wiki/going_further/', | ||
collapsable: true, | ||
children: [ | ||
'OPTIMIZATION', // Optimizing the game. | ||
'CUSTOM-MC', // Custom Minecraft! | ||
'MODPACKS', // Everything you need to know about Modpacks support. | ||
'PROBLEMATIC-MODS-COMMON-FIXES', // List of available fixes for popular modpacks. | ||
'ENV-VARS', // Using environment variables. | ||
'JAVA-ARGS', // Adding custom Java arguments. | ||
] | ||
|
||
} | ||
title: "Going Further", | ||
path: "/wiki/going_further/", | ||
collapsable: true, | ||
children: [ | ||
"OPTIMIZATION", // Optimizing the game. | ||
"CUSTOM-MC", // Custom Minecraft! | ||
"MODPACKS", // Everything you need to know about Modpacks support. | ||
"PROBLEMATIC-MODS-COMMON-FIXES", // List of available fixes for popular modpacks. | ||
"ENV-VARS", // Using environment variables. | ||
"JAVA-ARGS", // Adding custom Java arguments. | ||
], | ||
}; | ||
|
||
//// These are used to change the sidebar of their corresponding navbar counterpart. These don't use sidebar groups, instead they use the header as the title of the sidebar group (see Vuepress Documentation for more information on this behaviour). These sections are simple enough to not need custom shenanigans. | ||
|
||
export const about = [ | ||
'LEGAL', // Legal + Security. | ||
'DEVICES', // Supported Devices. | ||
'MCVERS', // Supported Minecraft Versions. | ||
'MODS-UNSUPPORTED', // Unsupported Mods. | ||
] | ||
"LEGAL", // Legal + Security. | ||
"DEVICES", // Supported Devices. | ||
"MCVERS", // Supported Minecraft Versions. | ||
"MODS-UNSUPPORTED", // Unsupported Mods. | ||
]; | ||
|
||
export const contribute = [ | ||
'CONT-WEBSITE', // Contributing to this website. | ||
'CONT-TRANSLATIONS', // Contributing to PojavLauncher translations, hopefully website translations later on. | ||
] | ||
"CONT-WEBSITE", // Contributing to this website. | ||
"CONT-TRANSLATIONS", // Contributing to PojavLauncher translations, hopefully website translations later on. | ||
]; | ||
|
||
export const patchnotes = [ | ||
'UNJAIL', // Bringing PojavLauncher to unjailbroken iOS. | ||
'IOS-SUPPORT', // System support in future versions of PojavLauncher iOS. | ||
'LOCAL-MODE', // Offline mode is going places. | ||
] | ||
"UNJAIL", // Bringing PojavLauncher to unjailbroken iOS. | ||
"IOS-SUPPORT", // System support in future versions of PojavLauncher iOS. | ||
"LOCAL-MODE", // Offline mode is going places. | ||
]; | ||
|
||
// Configuration Arrays | ||
|
||
/** Defines how groups are ordered within specific paths. */ | ||
export const GroupOrder = [ | ||
// This defines how groups are ordered within specific paths. So far, only the /wiki/ path uses this as it is the only path with sidebar groups. | ||
[ // /wiki/ | ||
'Getting_Started', 'FAQ', 'Going_Further' | ||
], | ||
[ // Unused | ||
'about' | ||
], | ||
[ // Unused | ||
'contribute' | ||
], | ||
[ // Unused | ||
'patchnotes' | ||
] | ||
] | ||
|
||
[ | ||
// /wiki/ | ||
"Getting_Started", | ||
"FAQ", | ||
"Going_Further", | ||
], | ||
[ | ||
// /about/ | ||
"about", | ||
], | ||
[ | ||
// /contribute/ | ||
"contribute", | ||
], | ||
[ | ||
// /patchnotes/ | ||
"patchnotes", | ||
], | ||
]; | ||
|
||
// This is just the regular nav configuration but it's in here instead of config.js because it makes more sense that way. | ||
/** This is just the regular vuepress nav configuration but it's in here instead of config.js because it looks nicer that way */ | ||
export const NavBar = [ | ||
{ text: 'Wiki', link: '/wiki/' }, | ||
{ text: 'About Pojavlauncher', link: '/about/DEVICES' }, | ||
{ text: 'Contributing', link: '/contribute/CONT-TRANSLATIONS' }, | ||
{ text: 'Recent Updates', link: '/patchnotes/IOS-SUPPORT' }, | ||
{ text: "Wiki", link: "/wiki/" }, | ||
{ text: "About Pojavlauncher", link: "/about/DEVICES" }, | ||
{ text: "Contributing", link: "/contribute/CONT-TRANSLATIONS" }, | ||
{ text: "Recent Updates", link: "/patchnotes/IOS-SUPPORT" }, | ||
]; | ||
|
||
] | ||
/** The logic needed to parse all of this for dynamic sidebar generation looks awful if it was defined here so it isn't. See ./bars.js */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,80 @@ | ||
const Arrays = require('./arrays.js'); | ||
const NavBar = require('./arrays.js').NavBar; | ||
const Arrays = require("./arrays.js"); | ||
const NavBar = require("./arrays.js").NavBar; | ||
const { GroupOrder } = Arrays; | ||
|
||
// Disgusting spam but readable | ||
const WikiSideBar = (GroupOrder[0]).map(category => generateSideBar(Arrays[category])); // Uses GroupOrder to generate wiki sidebar | ||
const AboutSideBar = (require('./arrays.js').about); // Just use page headers for sidebar | ||
const ContributeSideBar = (require('./arrays.js').contribute); | ||
const PatchSideBar = (require('./arrays.js').patchnotes); | ||
// Uses GroupOrder to generateSideBarOrder. The input is the indice of your array in GroupOrder. | ||
const WikiSideBar = generateSideBarOrder(0); | ||
const AboutSideBar = generateSideBarOrder(1); | ||
const ContributeSideBar = generateSideBarOrder(2); | ||
const PatchSideBar = generateSideBarOrder(3); | ||
|
||
// Defines path specified sidebars | ||
/** Defines path specified, generated sidebars */ | ||
const SideBar = { | ||
'/wiki/': WikiSideBar, | ||
'/about/': AboutSideBar, | ||
'/contribute/': ContributeSideBar, | ||
'/patchnotes/': PatchSideBar, | ||
} | ||
"/wiki/": WikiSideBar, | ||
"/about/": AboutSideBar, | ||
"/contribute/": ContributeSideBar, | ||
"/patchnotes/": PatchSideBar, | ||
}; | ||
|
||
module.exports = { SideBar, NavBar }; | ||
|
||
|
||
// WARNING: Everything below is just function definitions. | ||
// Do not touch if you don't understand. | ||
|
||
|
||
// Eats the path object and returns children with paths specified by path object. | ||
// Implements relative to parent pathing, just like prefix in Vuepress v2. | ||
/** | ||
* Eats the path object and returns children with paths specified by path object. | ||
* Implements relative to parent pathing, just like prefix in Vuepress v2, under object property `path`. | ||
* Only works with syntax for Group Sidebars. | ||
* Should not be used. Use generateSideBarOrder instead. | ||
* @param {string} arrays - Takes the name of a const and turns it into a sidebar. Will error on incorrect syntax in the object. | ||
* @returns {array} - A sidebar array | ||
*/ | ||
function generateSideBar(arrays) { | ||
// Recursively process the children array to handle nested objects | ||
/** Recursively process the children array to handle nested objects */ | ||
const processChildren = (children, parentPath) => { | ||
return children.map(child => { | ||
if (typeof child === 'string') { return parentPath + child; } // Affix parenthPath to children if string | ||
else { // If its not a string, assume it is a nested object and process like parent. | ||
return { | ||
return children.map((child) => { | ||
if (typeof child === "string") { | ||
return parentPath + child; | ||
} else { | ||
return { | ||
title: child.title, | ||
collapsable: child.collapsable !== undefined ? child.collapsable : true, // Default to true | ||
sidebarDepth: child.sidebarDepth || 2, // Default to 2 if not defined | ||
children: processChildren(child.children, parentPath + child.path + '/') // Recursively process children with parenthPath | ||
collapsable: | ||
child.collapsable !== undefined ? child.collapsable : true, // Default to true | ||
sidebarDepth: child.sidebarDepth || 2, // Default to 2 if not defined | ||
children: processChildren( | ||
child.children, | ||
parentPath + child.path + "/" | ||
), // Recursively process children with parenthPath | ||
}; | ||
} | ||
}); | ||
}; | ||
|
||
return { | ||
title: arrays.title, | ||
collapsable: arrays.collapsable !== undefined ? arrays.collapsable : true, | ||
sidebarDepth: arrays.sidebarDepth || 2, // Default to 2 if undefined | ||
children: processChildren(arrays.children, arrays.path) // Process the children | ||
collapsable: arrays.collapsable !== undefined ? arrays.collapsable : true, // Default to true | ||
sidebarDepth: arrays.sidebarDepth || 2, // Default to 2 if not defined | ||
children: processChildren(arrays.children, arrays.path), // Process the children | ||
}; | ||
} | ||
/** | ||
* Checks the const given by GroupOrder and checks if it is an Array or Object. | ||
* Works with automatic sidebar generation via headers when given .md files. | ||
* Maps an array called GroupOrder that defines the order of appearance of Grouped Sidebars on the sidebar array. | ||
* @param {int} - Takes an indice of GroupOrder | ||
* @returns {array} - A sidebar array | ||
*/ | ||
function generateSideBarOrder(order) { | ||
var currentArray = GroupOrder[order].map((order) => { | ||
return Arrays[order]; | ||
}); // [0] is there because .map() returns the values within its own array. We don't want that when checking if currentArray is an object or not | ||
var isArr = | ||
Object.prototype.toString.call(currentArray[0]) == "[object Array]"; // Check if it is truly an array or an object | ||
if (isArr) { | ||
// If it is just an array, use headers to define SideBar | ||
return currentArray[0]; | ||
} else { | ||
// If it is an object, generate the sidebar according to its properties | ||
return GroupOrder[order].map((category) => { | ||
return generateSideBar(Arrays[category]); | ||
}); | ||
} | ||
} |