Removed old index and nav script
This commit is contained in:
parent
4fc0df679b
commit
d6d51da2ac
@ -1,59 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
class AkiNavigator {
|
||||
constructor(defaultView, fetchPath = 'content') {
|
||||
this.header = undefined;
|
||||
this.contentOutlet = undefined;
|
||||
this.defaultView = defaultView;
|
||||
this.fetchPath = fetchPath;
|
||||
|
||||
this.onExec();
|
||||
}
|
||||
|
||||
onExec() {
|
||||
this.header = document.querySelector('header');
|
||||
this.contentOutlet = document.querySelector('#router-outlet');
|
||||
|
||||
window.addEventListener('hashchange', () => this.displayView(window.location.hash.substr(1)));
|
||||
|
||||
if (window.location.hash) {
|
||||
this.displayView(window.location.hash.substr(1));
|
||||
} else if (typeof this.defaultView !== 'undefined') {
|
||||
this.displayView(this.defaultView);
|
||||
}
|
||||
}
|
||||
|
||||
removeChildren(element) {
|
||||
let count = element.childNodes.length;
|
||||
|
||||
while (count--) {
|
||||
element.removeChild(element.lastChild);
|
||||
}
|
||||
}
|
||||
|
||||
async fetchView(view) {
|
||||
const response = await fetch(`${this.fetchPath}/${view}.html`);
|
||||
const text = await response.text();
|
||||
|
||||
this.removeChildren(this.contentOutlet);
|
||||
this.contentOutlet.innerHTML = text;
|
||||
}
|
||||
|
||||
displayView(view) {
|
||||
this.fetchView(view);
|
||||
|
||||
const activeLinks = document.querySelectorAll('a[active]');
|
||||
const newActiveLinks = document.querySelectorAll(`a[href='#${view}']`);
|
||||
|
||||
if (activeLinks.length > 0) {
|
||||
activeLinks.forEach(link => link.removeAttribute('active'));
|
||||
}
|
||||
|
||||
newActiveLinks.forEach(newLink => newLink.setAttribute('active', ''));
|
||||
|
||||
this.contentOutlet.scrollTop = 0;
|
||||
|
||||
// FIXME: history push is fucked rn.
|
||||
// window.history.pushState(null, `${view}`, `#${view}`);
|
||||
}
|
||||
}
|
@ -1,166 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>SPT-AKI</title>
|
||||
<link rel="stylesheet" href="./assets/css/style.css">
|
||||
<link rel="stylesheet" href="./assets/css/prism.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<header aki-toolbar>
|
||||
<a class="left" href="../../index.html">
|
||||
<img class="logo" src="./assets/img/logo.png">
|
||||
<span class="title text2">
|
||||
<span>SPT-AKI - Docs</span>
|
||||
</span>
|
||||
</a>
|
||||
|
||||
<nav class="text2 right dropdown">
|
||||
<div class="dropdown-button">...</div>
|
||||
<div class="dropdown-content">
|
||||
<a href="https://www.sp-tarkov.com">Website</a>
|
||||
<a href="https://mods.sp-tarkov.com">Workshop</a>
|
||||
<a href="https://dev.sp-tarkov.com">Gitea</a>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<aside></aside>
|
||||
<div id="router-outlet" class="doc-typography">
|
||||
<div class="text2" style="align-items:center;display:flex;height:100%;justify-content: center;">
|
||||
<div aki-card>
|
||||
Select a guide on the left to get started.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
|
||||
<script src="./assets/js/prism.js"></script>
|
||||
<script src="./assets/js/aki-navigator.js"></script>
|
||||
<script>
|
||||
// TODO: keep updating old files and add them the the routes list
|
||||
// TODO: work on routes nesting
|
||||
const routes = {
|
||||
"SPT-AKI": {
|
||||
"About": "spt-aki/about.md",
|
||||
"Install": "spt-aki/install.md",
|
||||
"FAQ": "spt-aki/faq.md",
|
||||
},
|
||||
"Tutorials": {
|
||||
// Generalist tutorials (walkthrough projects)
|
||||
"Character profile": {
|
||||
"Edit character level": "tutorials/profile/edit_character_level.md",
|
||||
"Edit skill level": "tutorials/profile/edit_skill_level.md"
|
||||
},
|
||||
"Edit profiles": "tutorials/edit_profiles.md",
|
||||
"Edit weapons texture": "tutorials/edit_weapons_texture.md",
|
||||
"Edit weapons texture(images)": "tutorials/photoshop_texture_editing.md",
|
||||
"WorkInProgress": "demo.md"
|
||||
},
|
||||
"Modding": {
|
||||
// Here are guides only related to modifying the server/client.
|
||||
"WorkInProgress": "demo.md"
|
||||
},
|
||||
"Resources": {
|
||||
// Here are ressources (mostly ingame ids list) to help with modding.
|
||||
"Tutorials index": "resources/index.md",
|
||||
"Player profile": "resources/player_profile.md",
|
||||
"Quests": "resources/quests.md",
|
||||
"Locations": "resources/locations.md",
|
||||
"Item stats": "resources/items_stats.md",
|
||||
"Other": "resources/other.md",
|
||||
},
|
||||
"Development": {
|
||||
// Documents related to maintaining the project
|
||||
"Setup": "development/setup.md",
|
||||
"Dump data": "development/dump_data.md"
|
||||
},
|
||||
// "DEBUG": {
|
||||
// "** Markdown Demo": "demo.md"
|
||||
// },
|
||||
// "Tutorials-old":{
|
||||
// "Create a mod on SP-Tarkov": ".old/tutorials/create_a_mod.md", // TODO: Create a "modding 101 series"
|
||||
// "How to report a bug": ".old/tutorials/bug-report.md", // TODO: include in FAQ
|
||||
// "Editing differents things in my player profile": ".old/tutorials/edit_the_player_profile.md",
|
||||
// "Change some traders behaviour": ".old/tutorials/edit_traders_values.md",
|
||||
// "How to customize maps values": ".old/tutorials/edit_location_values.md",
|
||||
// "Change global values of the server": ".old/tutorials/edit_globals_values.md",
|
||||
// "Edit weapons textures": ".old/tutorials/edit_weapons_textures.md",
|
||||
// "Edit weapons textures with photoshop": ".old/tutorials/photoshop_texture_editing.md",
|
||||
// "Customize weather presets": ".old/tutorials/create_weather.md",
|
||||
// "Add new bundles to the game": ".old/tutorials/add_new_bundles.md"
|
||||
// },
|
||||
// "Modding":{
|
||||
// "All items stats resources":"resources/itemsStats_resources.md",
|
||||
// "All locations resources":"resources/locations_resources.md",
|
||||
// "All player profile resources":"resources/playerProfile_resources.md",
|
||||
// "All quest resources":"resources/quests_resources.md",
|
||||
// "All other resources":"resources/other_resources.md"
|
||||
// }
|
||||
};
|
||||
|
||||
/**
|
||||
* Populates the <aside> element in the page
|
||||
* based on the `routes` object content.
|
||||
*/
|
||||
function populateNav() {
|
||||
Object.entries(routes).forEach(([key, node]) => {
|
||||
const sectionTitle = document.createElement('div');
|
||||
sectionTitle.classList.add('subheader');
|
||||
sectionTitle.innerText = key;
|
||||
|
||||
const sectionList = document.createElement('ul');
|
||||
// sectionTitle.appendChild(sectionList);
|
||||
|
||||
Object.entries(node).forEach(([k, v]) => {
|
||||
const listItem = document.createElement('li');
|
||||
const link = document.createElement('a');
|
||||
link.innerText = k;
|
||||
link.href = `#${v}`;
|
||||
|
||||
listItem.appendChild(link);
|
||||
// listItem.setAttribute('link', v);
|
||||
// listItem.innerText = k;
|
||||
|
||||
// The nav binding
|
||||
listItem.addEventListener('click', e => {
|
||||
if (e.target && e.target.hasAttribute('link')) {
|
||||
window.location.hash = e.target.getAttribute('link');
|
||||
}
|
||||
});
|
||||
|
||||
sectionList.appendChild(listItem);
|
||||
});
|
||||
|
||||
const divider = document.createElement('hr');
|
||||
divider.setAttribute('aki-divider', '');
|
||||
|
||||
const nav = document.querySelector('aside');
|
||||
nav.appendChild(sectionTitle);
|
||||
nav.appendChild(sectionList);
|
||||
nav.appendChild(divider);
|
||||
});
|
||||
}
|
||||
|
||||
populateNav();
|
||||
|
||||
// Dirty override
|
||||
class AkiNavigatorDocs extends AkiNavigator {
|
||||
async fetchView(view) {
|
||||
const response = await fetch(`${this.fetchPath}/${view}`);
|
||||
const text = await response.text();
|
||||
|
||||
this.removeChildren(this.contentOutlet);
|
||||
this.contentOutlet.innerHTML = marked(text); // edited
|
||||
Prism.highlightAll(); // edited
|
||||
}
|
||||
}
|
||||
|
||||
const akiNavigator = new AkiNavigatorDocs("lol", 'md');
|
||||
</script>
|
||||
</body>
|
Loading…
x
Reference in New Issue
Block a user