| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- # Подключение мета информации
- document.head.insertAdjacentHTML 'beforeend', '<meta charset="UTF-8">'
- document.head.insertAdjacentHTML 'beforeend', '<meta name="viewport" content="width=device-width, initial-scale=1.0">'
- # Настройка tailwind
- #tailwind.config = require 'tailwind.config.js'
- # Подключение основных стилей
- document.head.insertAdjacentHTML('beforeend', '<style type="text/tailwindcss" file="main.css">' + stylFns['main.css'] + '</style>')
- document.head.insertAdjacentHTML('beforeend', '<style type="text/tailwindcss" file="app/DesignTokens.styl">' + stylFns['app/DesignTokens.styl'] + '</style>')
- document.head.insertAdjacentHTML('beforeend', '<style type="text/tailwindcss" file="app/app.styl">' + stylFns['app/app.styl'] + '</style>')
- globalThis.AppDB = new require('app/utils/AppDB')
- await globalThis.AppDB.init()
- # Маршруты
- routes = [
- { path: '/', component: require 'app/pages/Home' }
- #{ path: '/:path*', component: require 'app/pages/DocumentPage' }
- ]
- globalThis._ = {}
- # Глобальное определение vuejs приложения
- globalThis.app = Vue.createApp
- name: 'app'
- data: () ->
- return {
- appState:
- currentDocument: null
- currentLanguage: 'ru'
- currentTheme: 'dark'
- availableLanguages: ['ru', 'en', 'tj']
- loading: true
- error: null
- }
-
- beforeMount: ->
- globalThis._ = @
- # Устанавливаем тему из localStorage или по умолчанию
- theme = localStorage.getItem('theme') or 'dark'
- @appState.currentTheme = theme
- document.documentElement.setAttribute('data-theme', theme)
- computed:
- currentLanguage: ->
- @appState.currentLanguage
- watch:
- currentLanguage:
- handler: (newDoc) ->
- debug.dir newDoc
- @loadDocumentForPath(window.location.pathname)
- immediate: true
- methods:
- parse: (md)->
- marked.parse md
- initializeApp: ->
- # Определяем язык из URL или браузера
- @detectLanguage()
- # Загружаем документ для текущего пути
- @loadDocumentForPath(window.location.pathname)
-
- detectLanguage: ->
- # Простая логика определения языка
- pathLang = window.location.pathname.split('/')[1]
- if pathLang in @appState.availableLanguages
- @appState.currentLanguage = pathLang
- else
- browserLang = navigator.language.split('-')[0]
- if browserLang in @appState.availableLanguages
- @appState.currentLanguage = browserLang
-
- loadDocumentForPath: (path) ->
- try
- @appState.loading = true
- debug.log ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
- doc = await AppDB.getDocumentByPath(path, AppDB.currentLanguage)
- debug.dir doc
- debug.log "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
- @appState.currentDocument = doc
- @appState.loading = false
-
- # Устанавливаем заголовок страницы
- if doc?.title
- document.head.insertAdjacentHTML('beforeend', '<title>' + doc.title + '</title>')
- catch error
- @appState.error = "Ошибка загрузки документа: " + error
- @appState.loading = false
-
-
- render: (new Function '_ctx', '_cache', renderFns['app/app.pug'])()
-
- components: {
- 'hero-section': require('app/shared/HeroSection')
- 'image-gallery': require('app/shared/ImageGallery')
- }
- # Создаем и настраиваем роутер
- router = VueRouter.createRouter({
- routes: routes
- history: VueRouter.createWebHistory()
- scrollBehavior: (to, from, savedPosition) ->
- if savedPosition
- return savedPosition
- else
- return { x: 0, y: 0 }
- })
- app.use(router)
- app.mount('body')
|