app.coffee 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. # Маршруты
  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. marked: marked
  22. appState:
  23. currentDocument: null
  24. currentLanguage: 'ru'
  25. availableLanguages: ['ru', 'en', 'tj']
  26. loading: true
  27. error: null
  28. }
  29. beforeMount: ->
  30. globalThis.AppDB = new (require 'app/utils/AppDB')()
  31. await globalThis.AppDB.init()
  32. globalThis._ = @
  33. computed:
  34. currentLanguage: ->
  35. @appState.currentLanguage
  36. watch:
  37. currentLanguage:
  38. handler: (newDoc) ->
  39. debug.dir newDoc
  40. @loadDocumentForPath(window.location.pathname)
  41. immediate: true
  42. methods:
  43. initializeApp: ->
  44. # Определяем язык из URL или браузера
  45. @detectLanguage()
  46. # Загружаем документ для текущего пути
  47. @loadDocumentForPath(window.location.pathname)
  48. detectLanguage: ->
  49. # Простая логика определения языка
  50. pathLang = window.location.pathname.split('/')[1]
  51. if pathLang in @appState.availableLanguages
  52. @appState.currentLanguage = pathLang
  53. else
  54. browserLang = navigator.language.split('-')[0]
  55. if browserLang in @appState.availableLanguages
  56. @appState.currentLanguage = browserLang
  57. loadDocumentForPath: (path) ->
  58. try
  59. @appState.loading = true
  60. debug.log ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
  61. doc = await AppDB.getDocumentByPath(path, AppDB.currentLanguage)
  62. debug.dir doc
  63. debug.log "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
  64. @appState.currentDocument = doc
  65. @appState.loading = false
  66. # Устанавливаем заголовок страницы
  67. if doc?.title
  68. document.head.insertAdjacentHTML('beforeend', '<title>' + doc.title + '</title>')
  69. catch error
  70. @appState.error = "Ошибка загрузки документа: " + error
  71. @appState.loading = false
  72. render: (new Function '_ctx', '_cache', renderFns['app/app.pug'])()
  73. components: {
  74. 'hero-section': require('app/shared/HeroSection')
  75. 'image-gallery': require('app/shared/ImageGallery')
  76. }
  77. # Создаем и настраиваем роутер
  78. router = VueRouter.createRouter({
  79. routes: routes
  80. history: VueRouter.createWebHistory()
  81. scrollBehavior: (to, from, savedPosition) ->
  82. if savedPosition
  83. return savedPosition
  84. else
  85. return { x: 0, y: 0 }
  86. })
  87. app.use(router)
  88. app.mount('body')