Static.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <MainContentLayout
  3. id="static"
  4. :reftoscrollto="reftoscrollto"
  5. >
  6. <template v-slot:header>
  7. <span v-if="!page" class="loading">Chargement ...</span>
  8. <template v-else>
  9. <h1>{{ page.title }}</h1>
  10. <nav v-if="toc" class="toc" :class="{ opened: sommaireopened }">
  11. <span
  12. class="sommaire-title"
  13. @click.prevent="onOpenCloseSommaire"
  14. @keyup.enter="onOpenCloseSommaire"
  15. >
  16. <svg xmlns="http://www.w3.org/2000/svg" width="14" height="10" role="presentation" class="vs__open-indicator"><path d="M9.211364 7.59931l4.48338-4.867229c.407008-.441854.407008-1.158247 0-1.60046l-.73712-.80023c-.407008-.441854-1.066904-.441854-1.474243 0L7 5.198617 2.51662.33139c-.407008-.441853-1.066904-.441853-1.474243 0l-.737121.80023c-.407008.441854-.407008 1.158248 0 1.600461l4.48338 4.867228L7 10l2.211364-2.40069z" /></svg>
  17. Sommaire
  18. </span>
  19. <div class="wrapper">
  20. <ul>
  21. <li
  22. v-for="(item,index) in toc"
  23. :key="index"
  24. >
  25. <a
  26. :href="'#' + item.hash"
  27. @click.prevent="onclickTOC"
  28. @keyup.enter="onclickTOC"
  29. >
  30. {{ item.title }}
  31. </a>
  32. </li>
  33. </ul>
  34. </div>
  35. </nav>
  36. </template>
  37. </template>
  38. <div v-if="page" v-html="page.tei_parsed" />
  39. </MainContentLayout>
  40. </template>
  41. <script>
  42. import { mapState, mapActions } from 'vuex'
  43. import MainContentLayout from '../components/Layouts/MainContentLayout'
  44. export default {
  45. name: 'Static',
  46. components: {
  47. MainContentLayout
  48. },
  49. data: () => ({
  50. uuid: null,
  51. page: null,
  52. toc: [],
  53. reftoscrollto: null,
  54. sommaireopened: false
  55. }),
  56. computed: {
  57. ...mapState({
  58. colophon: state => state.Colophon.colophon
  59. })
  60. // page () {
  61. // }
  62. },
  63. watch: {
  64. $route (n, o) {
  65. console.log('static route changed', n, o)
  66. this.uuid = n.name
  67. if (this.colophon && this.colophon.length > 0) {
  68. this.setPage()
  69. }
  70. },
  71. colophon (n, o) {
  72. this.setPage()
  73. }
  74. },
  75. beforeCreate () {
  76. },
  77. created () {
  78. if (!this.colophon.length) {
  79. this.getColophon()
  80. }
  81. console.log('Static created', this.$route)
  82. this.uuid = this.$route.name
  83. if (this.colophon && this.colophon.length > 0) {
  84. this.setPage()
  85. }
  86. },
  87. methods: {
  88. ...mapActions({
  89. getColophon: 'Colophon/getColophon'
  90. }),
  91. setPage () {
  92. for (let i = 0; i < this.colophon.length; i++) {
  93. if (this.colophon[i].uuid === this.uuid) {
  94. this.page = this.colophon[i]
  95. }
  96. }
  97. this.parseContentImages()
  98. this.parseContentTOC()
  99. },
  100. parseContentImages () {
  101. console.log('parseContentImages')
  102. this.page.tei_parsed = this.page.tei.replace(/src="\/gdp\/static\/images\/(\w+)\.jpg"/g, `src="${window.apipath}/gdp/static/images/$1.jpg"`)
  103. // console.log(this.page.tei_parsed)
  104. },
  105. parseContentTOC () {
  106. let match = this.page.tei_parsed.match(/<h1[^>]*>[^<]+<\/h1>/g)
  107. console.log('match', match)
  108. match.forEach((element, index) => {
  109. console.log(element, index)
  110. // let elmt = element.replace(/<h1([^>]*)>([^<]+)<\/h1>/, `<h1 id="toc-${index}"$1>$2</h1>`)
  111. let elmtmatch = element.match(/(<h1([^>]*)>)([^<]+)<\/h1>/)
  112. let elmt = element.replace(elmtmatch[1], `<h1 id="toc-${index}"${elmtmatch[2]}>`)
  113. this.page.tei_parsed = this.page.tei_parsed.replace(element, elmt)
  114. this.toc.push({
  115. title: elmtmatch[3],
  116. hash: `toc-${index}`
  117. })
  118. })
  119. },
  120. onOpenCloseSommaire (e) {
  121. console.log('onOpenCloseSommaire', e)
  122. this.sommaireopened = !this.sommaireopened
  123. },
  124. onclickTOC (e) {
  125. console.log('onClickTOC', e, e.target.hash)
  126. this.reftoscrollto = e.target.hash
  127. }
  128. },
  129. metaInfo () {
  130. return {
  131. title: `Static`
  132. }
  133. }
  134. }
  135. </script>
  136. <style lang="scss" scoped>
  137. </style>