app.coffee 4.2 KB

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