mirror of
https://github.com/janishutz/libreevent.git
synced 2025-11-25 21:34:24 +00:00
website build script almost complete
This commit is contained in:
@@ -3,7 +3,7 @@ The main website's pages are written in HTML & CSS whilst the doc pages are auto
|
|||||||
** DO NOT MODIFY THE DOC PAGES IN THE [dist/docs/](dist/docs/) DIRECTORY! **
|
** DO NOT MODIFY THE DOC PAGES IN THE [dist/docs/](dist/docs/) DIRECTORY! **
|
||||||
|
|
||||||
## Links in the md files in [src/](src/)
|
## Links in the md files in [src/](src/)
|
||||||
Please note that you are required to use either a link relative to the root folder with double forward slash (example: *//server/app.js*), to the website root with a single forward slash (example: */download*), to the docs root with &/ (example: *&/setup*) or simply /docs/ (example: */docs/setup*), a full link (example: *https://libreevent.janishutz.com/docs*) or a relative link (example: *plugins/music*). If you do not follow these patterns, the website won't build or the links will not work correctly.
|
Please note that you are required to use either a link relative to the root folder with double forward slash (example: *//server/app.js*), to the website root with a single forward slash (example: */download*), to the docs root with &/ (example: *&/setup*) or simply /docs/ (example: */docs/setup*), a full link (example: *https://libreevent.janishutz.com/docs*) or a relative link (example: *plugins/music*). Note that *../* relative links are NOT intended to be used and will lead to an error when building the docs! If you do not follow these patterns, the website won't build or the links will not work correctly.
|
||||||
|
|
||||||
***NOTE: Don't be confused if the root folder links don't work in the Markdown, as they use specific syntax for the build script.***
|
***NOTE: Don't be confused if the root folder links don't work in the Markdown, as they use specific syntax for the build script.***
|
||||||
|
|
||||||
|
|||||||
@@ -14,16 +14,19 @@ const path = require( 'path' );
|
|||||||
|
|
||||||
buildNav( buildDocs() );
|
buildNav( buildDocs() );
|
||||||
|
|
||||||
|
|
||||||
function buildNav ( pathObject ) {
|
function buildNav ( pathObject ) {
|
||||||
console.log( 'building nav ' + pathObject );
|
console.log( 'building nav ' + pathObject );
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildDocs () {
|
function buildDocs () {
|
||||||
|
let allFiles = [];
|
||||||
|
|
||||||
let directoriesToScan = [];
|
let directoriesToScan = [];
|
||||||
let files = fs.readdirSync( path.join( __dirname + '/src/' ) );
|
let files = fs.readdirSync( path.join( __dirname + '/src/' ) );
|
||||||
for ( let file in files ) {
|
for ( let file in files ) {
|
||||||
if ( files[ file ].substring( files[ file ].length - 3 ) == '.md' ) {
|
if ( files[ file ].substring( files[ file ].length - 3 ) == '.md' ) {
|
||||||
handleMD( files[ file ] );
|
allFiles.push( handleMD( path.join( __dirname + '/src/' + files[ file ] ) ) );
|
||||||
} else {
|
} else {
|
||||||
directoriesToScan.push( files[ file ] );
|
directoriesToScan.push( files[ file ] );
|
||||||
}
|
}
|
||||||
@@ -37,7 +40,7 @@ function buildDocs () {
|
|||||||
count -= 1;
|
count -= 1;
|
||||||
for ( let file in files ) {
|
for ( let file in files ) {
|
||||||
if ( files[ file ].substring( files[ file ].length - 3 ) == '.md' ) {
|
if ( files[ file ].substring( files[ file ].length - 3 ) == '.md' ) {
|
||||||
handleMD( files[ file ] );
|
allFiles.push( handleMD( path.join( __dirname + '/src/' + directoriesToScan[ missing ] + '/' + files[ file ] ) ) );
|
||||||
} else {
|
} else {
|
||||||
directoriesToScan.push( directoriesToScan[ missing ] + '/' + files[ file ] );
|
directoriesToScan.push( directoriesToScan[ missing ] + '/' + files[ file ] );
|
||||||
count += 1;
|
count += 1;
|
||||||
@@ -45,10 +48,81 @@ function buildDocs () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
md2html.render( '#Test' );
|
return allFiles;
|
||||||
return 'Hi';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleMD ( path ) {
|
function handleMD ( filepath ) {
|
||||||
console.log( 'md file', path );
|
let fileContent = md2html.render( fs.readFileSync( filepath ).toString() );
|
||||||
|
for ( let letter in fileContent ) {
|
||||||
|
if ( fileContent[ letter ] == '<' ) {
|
||||||
|
if ( fileContent.slice( parseInt( letter ), parseInt( letter ) + 9 ) === '<a href="' ) {
|
||||||
|
let newLink = '';
|
||||||
|
let i = 9;
|
||||||
|
while ( fileContent.slice( parseInt( letter ) + i, parseInt( letter ) + i + 1 ) !== '"' ) {
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
let link = fileContent.slice( parseInt( letter ) + 9, parseInt( letter ) + i );
|
||||||
|
if ( link.slice( 0, 1 ) === '/' || link.slice( 0, 8 ) === 'https://' || link.slice( 0, 7 ) === 'http://' || link.slice( 0, 1 ) !== '/' && link.slice( 0, 1 ) !== '&' ) {
|
||||||
|
newLink = '<a href="' + link + '">';
|
||||||
|
} else if ( link.slice( 0, 2 ) == '&/' ) {
|
||||||
|
newLink = '<a href="/docs/' + link.substring( 2 ) + '">';
|
||||||
|
} else if ( link.slice( 0, 6 ) == '&/' ) {
|
||||||
|
newLink = '<a href="/docs/' + link.substring( 6 ) + '">';
|
||||||
|
} else if ( link.slice( 0, 2 ) == '//' ) {
|
||||||
|
if ( link.includes( '.' ) ) {
|
||||||
|
newLink = '<a href="https://github.com/simplePCBuilding/libreevent/blob/master/' + link.substring( 2 ) + '">';
|
||||||
|
} else {
|
||||||
|
newLink = '<a href="https://github.com/simplePCBuilding/libreevent/tree/master/' + link.substring( 2 ) + '">';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.error( 'Unsupported link: ' + link );
|
||||||
|
throw 'INVALID LINK FOUND IN PLUGINS README! Please fix and rerun the script';
|
||||||
|
}
|
||||||
|
fileContent = fileContent.slice( 0, parseInt( letter ) ) + newLink + fileContent.slice( parseInt( letter ) + i + 2, parseInt( fileContent.length ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return storeHTML( fileContent, filepath );
|
||||||
|
}
|
||||||
|
|
||||||
|
function storeHTML( html, filepath ) {
|
||||||
|
/*
|
||||||
|
TODO: Guess doc page title from first H1 Element.
|
||||||
|
*/
|
||||||
|
let data = `<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>${ filepath } :: DOCS - libreevent</title>
|
||||||
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
|
||||||
|
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
||||||
|
<script src="/js/docs/loader.js"></script>
|
||||||
|
<link rel="stylesheet" href="/css/docs/style.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="content">
|
||||||
|
<div id="nav"></div>
|
||||||
|
<div id="top"></div>
|
||||||
|
<div id="docPage">
|
||||||
|
<div id="doc-container">
|
||||||
|
${ html }</div>
|
||||||
|
</div>
|
||||||
|
<div id="footer"></div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>`;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Transform file path into correct file structure and output file to dist/docs folder
|
||||||
|
*/
|
||||||
|
let fileOutputPath = path.join( __dirname + '/dist/docs' );
|
||||||
|
let pos = filepath.indexOf( 'src' );
|
||||||
|
fileOutputPath += filepath.substring( parseInt( pos ) + 3, filepath.length - 3 );
|
||||||
|
try {
|
||||||
|
fs.mkdirSync( fileOutputPath, { recursive: true } );
|
||||||
|
} catch ( error ) {
|
||||||
|
null;
|
||||||
|
}
|
||||||
|
fileOutputPath += '/index.html';
|
||||||
|
fs.writeFileSync( fileOutputPath, data );
|
||||||
|
return fileOutputPath;
|
||||||
}
|
}
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
# libreevent - documentation
|
|
||||||
Welcome to the libreevent documentation! Here you may learn how to set up a libreevent-server instance, how to configure it and how to install plugins. You may also learn how to develop your own plugin and what you need to know if you want to contribute to the project.
|
|
||||||
Reference in New Issue
Block a user