diff --git a/.gitignore b/.gitignore
index fd8297e..c65f9ee 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,11 @@
.parcel-cache/
-.parcel-app/
-ec*.exe
-public/
+
content/
app/bootstrap*
+
+# new env
+dev/
+dist/
+
+# for windows
+ec*.exe
diff --git a/.prettierignore b/.prettierignore
index a6bfe87..6a5eeda 100644
--- a/.prettierignore
+++ b/.prettierignore
@@ -1,8 +1,5 @@
-public/
-static/
app/assets/css/bootstrap*
app/assets/js/bootstrap*
-package.json
package-lock.json
server/
*.md
diff --git a/README.md b/README.md
index 0483fe9..fc7bd18 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
## Используемые технологии
- **Языки:** **JavaScript** для фрота, **Crystal** для бэка и **Bash** для скриптов.
-- **Инструменты:** Parcel, Prettier, EditorConfig
+- **Инструменты:** Parcel, Prettier, EditorConfig, nginx
## Сборка
diff --git a/app/app.js b/app/app.js
index 91ce382..ea6b57e 100644
--- a/app/app.js
+++ b/app/app.js
@@ -22,7 +22,17 @@ window.onload = function () {
document.getElementById('app_theme_switcher').addEventListener('click', switch_theme, false);
// routes handler
- window.addEventListener('hashchange', location_handler);
+ document.addEventListener('click', (e) => {
+ const { target } = e;
+ if (!target.matches('nav a')) {
+ return;
+ }
+ e.preventDefault();
+ route();
+ });
+
+ window.onpopstate = location_handler;
+ window.route = route;
location_handler();
};
@@ -46,11 +56,24 @@ function switch_theme() {
}
}
+const route = (event) => {
+ event = event || window.event; // get window.event if event argument not provided
+ event.preventDefault();
+ // window.history.pushState(state, unused, target link);
+ window.history.pushState({}, '', event.target.href);
+ location_handler();
+};
+
const location_handler = async () => {
- let location = window.location.hash.replace('#', '');
- if (location.length == 0) {
+ const url = window.location.pathname;
+ let location;
+
+ if (url == 0 || url == '/') {
location = '/';
+ } else {
+ location = url.slice(1);
}
+
const route = routes[location] || routes['404'];
const html = await fetch(route.template).then((response) => response.text());
document.getElementById('content').innerHTML = html;
@@ -58,11 +81,19 @@ const location_handler = async () => {
document.querySelector('meta[name="description"]').setAttribute('content', route.description);
if (route.script) {
- let script = document.getElementById('content').querySelector('script');
- document.querySelector('#autorun').innerHTML = script.innerHTML;
- script.remove();
+ const route_script = document.getElementById('content').querySelector('script');
+ let autorun_script = document.querySelector('#autorun');
- eval(document.querySelector('#autorun').innerHTML);
+ // инициализирует новый блок кода
+ autorun_script.remove();
+ autorun_script = document.createElement('script');
+ autorun_script.setAttribute('type', 'module');
+ autorun_script.setAttribute('id', 'autorun');
+ autorun_script.innerHTML = route_script.innerHTML;
+
+ // удаляет скрипт из загруженной страницы и запускает новый
+ route_script.remove();
+ document.body.append(autorun_script);
} else {
document.querySelector('#autorun').innerHTML = '';
}
diff --git a/app/humans.txt b/app/humans.txt
index bc7a7e9..1b73c4b 100644
--- a/app/humans.txt
+++ b/app/humans.txt
@@ -1,9 +1,9 @@
/* SITE */
-Last update: Sun Aug 06 04:57 AM MSK 2023
+Last update: Sun Aug 19 02:47 AM MSK 2023
Language: Russian
Doctype: HTML5
IDE: Sublime Text 4
-Tools: Parcel, Prettier, EditorConfig
+Tools: Parcel, Prettier, EditorConfig, nginx
Components: Bootstrap 5.3.1
Server: 1Gb RAM 1CPU KVM by FirstVDS
Server OS: ArchLinux rolling
diff --git a/app/partitial/header.html b/app/partitial/header.html
index 182580a..ffcfa65 100644
--- a/app/partitial/header.html
+++ b/app/partitial/header.html
@@ -23,7 +23,7 @@
Home
-
+