Skip to content

Commit

Permalink
🎯 feats: Implementação de um sistema de nested routes para site da In…
Browse files Browse the repository at this point in the history
…foDocs
  • Loading branch information
ruancarllo committed Jul 23, 2024
1 parent 99337a7 commit 2e15b0f
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 11 deletions.
Binary file added source/backend/assets/infojr-banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions source/backend/templates/nested-route.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html>
<head>
<title>$TITLE</title>
<meta name="theme-color" content="COLOR">
<meta charset="utf-8">
<meta property="og:url" content="URL">
<meta property="og:type" content="website">
<meta property="og:title" content="TITLE">
<meta property="og:image" content="IMAGE">
<meta property="og:description" content="DESCRIPTION">
<script>
window.location.replace("NESTED-ROUTE");
</script>
<style>
* {
margin: 0;
border: 0;
padding: 0;
box-sizing: border-box;
}

body {
width: 100vw;
width: 100dvw;

height: 100vh;
height: 100dvh;

display: flex;
align-items: center;
justify-content: center;

background-color: COLOR;
}
</style>
</head>
<body></body>
</html>
56 changes: 45 additions & 11 deletions source/backend/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ class Directories {

static serverTemplates = {
subRoute: path.join(__dirname, 'templates', 'sub-route.html'),
nestedRoute: path.join(__dirname, 'templates', 'nested-route.html'),
}
}

class Routing {
static registeredEntries: {[subRoute: string]: {url: string, title: string, description: string, image: string, color: string}} = {
static registeredEntries: {[subRoute: string]: {url: string, title: string, description: string, image: string, color: string, nested?: string[]}} = {
'quasar': {
title: 'Quasar',
description: 'O seu aplicativo de estudos',
Expand All @@ -32,10 +33,22 @@ class Routing {
url: 'https://ruancarllo.github.io/unesp',
image: 'https://raw.githubusercontent.com/ruancarllo/portfolio/main/source/backend/assets/unesp-banner.png',
color: '#020617'
},
'infodocs': {
title: 'InfoDocs',
description: 'Conglomerado de documentações para a InfoJr',
url: 'https://ruancarllo.github.io/infojr/docs',
image: 'https://raw.githubusercontent.com/ruancarllo/portfolio/main/source/backend/assets/infojr-banner.png',
color: '#161244',
nested: [
'wordpress-agil',
'wordpress-guia'
]
}
}

static pageTemplate = fs.readFileSync(Directories.serverTemplates.subRoute, 'utf-8');
static subRouteTemplate = fs.readFileSync(Directories.serverTemplates.subRoute, 'utf-8');
static nestedRouteTemplate = fs.readFileSync(Directories.serverTemplates.nestedRoute, 'utf-8');
}

async function serve() {
Expand Down Expand Up @@ -79,18 +92,39 @@ async function build() {

async function route() {
for (let subRoute in Routing.registeredEntries) {
const subRouteURL = Routing.registeredEntries[subRoute];
const subRouteObject = Routing.registeredEntries[subRoute];

if (subRouteObject.nested === undefined) {
let subRoutePage = Routing.subRouteTemplate;
subRoutePage = subRoutePage.replaceAll('SUB-ROUTE', subRouteObject.url);
subRoutePage = subRoutePage.replaceAll('TITLE', subRouteObject.title);
subRoutePage = subRoutePage.replaceAll('IMAGE', subRouteObject.image);
subRoutePage = subRoutePage.replaceAll('DESCRIPTION', subRouteObject.description);
subRoutePage = subRoutePage.replaceAll('COLOR', subRouteObject.color);

const subRoutePath = path.join(Directories.websiteTarget, `${subRoute}.html`);

fs.writeFileSync(subRoutePath, subRoutePage);
}

let subRoutePage = Routing.pageTemplate;
subRoutePage = subRoutePage.replaceAll('SUB-ROUTE', subRouteURL.url);
subRoutePage = subRoutePage.replaceAll('TITLE', subRouteURL.title);
subRoutePage = subRoutePage.replaceAll('IMAGE', subRouteURL.image);
subRoutePage = subRoutePage.replaceAll('DESCRIPTION', subRouteURL.description);
subRoutePage = subRoutePage.replaceAll('COLOR', subRouteURL.color);
else {
const subRouteFolder = path.join(Directories.websiteTarget, subRoute);

const subRoutePath = path.join(Directories.websiteTarget, `${subRoute}.html`);
fs.mkdirSync(subRouteFolder, {recursive: true});

fs.writeFileSync(subRoutePath, subRoutePage);
for (let nestedRoute of subRouteObject.nested) {
let nestedRoutePage = Routing.nestedRouteTemplate;
nestedRoutePage = nestedRoutePage.replaceAll('NESTED-ROUTE', `${subRouteObject.url}/${nestedRoute}`);
nestedRoutePage = nestedRoutePage.replaceAll('TITLE', subRouteObject.title);
nestedRoutePage = nestedRoutePage.replaceAll('IMAGE', subRouteObject.image);
nestedRoutePage = nestedRoutePage.replaceAll('DESCRIPTION', subRouteObject.description);
nestedRoutePage = nestedRoutePage.replaceAll('COLOR', subRouteObject.color);

const nestedRoutePath = path.join(Directories.websiteTarget, subRoute, `${nestedRoute}.html`);

fs.writeFileSync(nestedRoutePath, nestedRoutePage);
}
}
}
}

Expand Down

0 comments on commit 2e15b0f

Please sign in to comment.