From 34aee6e4cb3e9788327f1ff66412aa9477e8659b Mon Sep 17 00:00:00 2001 From: Alexander Popov Date: Sat, 19 Aug 2023 03:18:03 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D1=91=D0=BD=20?= =?UTF-8?q?=D1=82=D0=B8=D0=BF=20=D1=80=D0=BE=D1=83=D1=82=D0=B5=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=20=D1=81=20#=20=D0=BD=D0=B0=20/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 11 +- .prettierignore | 3 - README.md | 2 +- app/app.js | 45 +++++-- app/humans.txt | 4 +- app/partitial/header.html | 2 +- app/partitial/menu.html | 241 +++++++++++++++++++++----------------- package.json | 14 +-- pages/personal.html | 2 +- pages/rer2.html | 2 +- update_commit.sh | 4 +- 11 files changed, 195 insertions(+), 135 deletions(-) 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 - + -
  • - - - - - Games - -
  • -
  • -
  • - - - - - - Буква ё - -
  • -
  • -
  • - - - - - - - Git инстанс - -
  • -
  • -
  • - - - - - - Personal - -
  • -
  • - - - - - - - - Trash - -
  • - + diff --git a/package.json b/package.json index afaa5b9..1234150 100644 --- a/package.json +++ b/package.json @@ -1,18 +1,16 @@ { "private": true, "name": "a2s", - "version": "1.0.0", + "version": "0.0.0", "description": "ololo", "scripts": { - "serve": "npx parcel serve --dist-dir .parcel-app app/index.html icons/*.png pages/*.html content/*/*/*", - "serve-https": "npx parcel serve --https --dist-dir public app/index.html pages/*.html content/*/*/*", - "build": "npm run clean; npm run build-pages; npm run build-app; npm run git-hash", - "build-app": "npx parcel build --no-cache --no-source-maps --no-optimize --no-content-hash --dist-dir public app/index.html", - "build-pages": "npx parcel build --no-cache --no-source-maps --no-optimize --no-content-hash --dist-dir public/ content/*/*/* pages/*.html", + "develop": "npm run clean; ln -s pages/ dev/pages/; npm run watch-app", + "watch-app": "npx parcel watch --dist-dir dev/ app/index.html", + "build": "npm run clean; npm run build-app; npm run git-hash", + "build-app": "npx parcel build --no-cache --no-source-maps --no-optimize --no-content-hash --dist-dir dist/ app/index.html", "prettier": "npx prettier --write .", "git-hash": "./update_commit.sh", - "clean": "rm -rf ./public/ &> /dev/null", - "test": "echo \"Error: no test specified\" && exit 1" + "clean": "rm -rf ./dev/* ./dist/* &> /dev/null" }, "author": "Alexander Popov ", "license": "WTFPL", diff --git a/pages/personal.html b/pages/personal.html index a959cb8..a0600d2 100644 --- a/pages/personal.html +++ b/pages/personal.html @@ -23,7 +23,7 @@