app.coffee 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. # Подключение мета информации
  2. document.head.insertAdjacentHTML 'beforeend', '<meta charset="UTF-8">'
  3. document.head.insertAdjacentHTML 'beforeend', '<meta name="viewport" content="width=device-width, initial-scale=1.0">'
  4. # Настройка tailwind
  5. #tailwind.config = require 'tailwind.config.js'
  6. # Подключение основных стилей
  7. document.head.insertAdjacentHTML('beforeend', '<style type="text/css" file="main.css">' + stylFns['main.css'] + '</style>')
  8. document.head.insertAdjacentHTML('beforeend', '<style type="text/css" file="app/DesignTokens.styl">' + stylFns['app/DesignTokens.styl'] + '</style>')
  9. document.head.insertAdjacentHTML('beforeend', '<style type="text/css" file="app/app.styl">' + stylFns['app/app.styl'] + '</style>')
  10. # Маршруты
  11. routes = [
  12. { path: '/', component: require 'app/pages/Home' }
  13. #{ path: '/:path*', component: require 'app/pages/DocumentPage' }
  14. ]
  15. globalThis._ = {}
  16. # Глобальное определение vuejs приложения
  17. globalThis.app = Vue.createApp
  18. name: 'app'
  19. data: () ->
  20. return {
  21. appState:
  22. currentDocument: null
  23. currentLanguage: 'ru'
  24. currentTheme: 'dark'
  25. availableLanguages: ['ru', 'en', 'tj']
  26. loading: true
  27. error: null
  28. }
  29. beforeMount: ->
  30. globalThis._ = @
  31. # Устанавливаем тему из localStorage или по умолчанию
  32. theme = localStorage.getItem('theme') or 'dark'
  33. @appState.currentTheme = theme
  34. document.documentElement.setAttribute('data-theme', theme)
  35. computed:
  36. currentLanguage: ->
  37. @appState.currentLanguage
  38. watch:
  39. currentLanguage:
  40. handler: (newDoc) ->
  41. debug.dir newDoc
  42. @loadDocumentForPath(window.location.pathname)
  43. immediate: true
  44. methods:
  45. parse: (md)->
  46. marked.parse md
  47. initializeApp: ->
  48. # Определяем язык из URL или браузера
  49. @detectLanguage()
  50. # Загружаем документ для текущего пути
  51. @loadDocumentForPath(window.location.pathname)
  52. detectLanguage: ->
  53. # Простая логика определения языка
  54. pathLang = window.location.pathname.split('/')[1]
  55. if pathLang in @appState.availableLanguages
  56. @appState.currentLanguage = pathLang
  57. else
  58. browserLang = navigator.language.split('-')[0]
  59. if browserLang in @appState.availableLanguages
  60. @appState.currentLanguage = browserLang
  61. loadDocumentForPath: (path) ->
  62. try
  63. @appState.loading = true
  64. debug.log ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
  65. doc = await AppDB.getDocumentByPath(path, AppDB.currentLanguage)
  66. debug.dir doc
  67. debug.log "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
  68. @appState.currentDocument = doc
  69. @appState.loading = false
  70. # Устанавливаем заголовок страницы
  71. if doc?.title
  72. document.head.insertAdjacentHTML('beforeend', '<title>' + doc.title + '</title>')
  73. catch error
  74. @appState.error = "Ошибка загрузки документа: " + error
  75. @appState.loading = false
  76. render: (new Function '_ctx', '_cache', renderFns['app/app.pug'])()
  77. components: {
  78. 'hero-section': require('app/shared/HeroSection')
  79. 'image-gallery': require('app/shared/ImageGallery')
  80. }
  81. # Создаем и настраиваем роутер
  82. router = VueRouter.createRouter({
  83. routes: routes
  84. history: VueRouter.createWebHistory()
  85. scrollBehavior: (to, from, savedPosition) ->
  86. if savedPosition
  87. return savedPosition
  88. else
  89. return { x: 0, y: 0 }
  90. })
  91. app.use(router)
  92. app.mount('body')