Static.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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">
  11. <ul>
  12. <li
  13. v-for="(item,index) in toc"
  14. :key="index"
  15. >
  16. <a
  17. :href="'#' + item.hash"
  18. @click.prevent="onclickTOC"
  19. @keyup.enter="onclickTOC"
  20. >
  21. {{ item.title }}
  22. </a>
  23. </li>
  24. </ul>
  25. </nav>
  26. </template>
  27. </template>
  28. <div v-if="page" v-html="page.tei_parsed" />
  29. </MainContentLayout>
  30. </template>
  31. <script>
  32. import { mapState, mapActions } from 'vuex'
  33. import MainContentLayout from '../components/Layouts/MainContentLayout'
  34. export default {
  35. name: 'Static',
  36. components: {
  37. MainContentLayout
  38. },
  39. data: () => ({
  40. uuid: null,
  41. page: null,
  42. toc: [],
  43. reftoscrollto: null
  44. }),
  45. computed: {
  46. ...mapState({
  47. colophon: state => state.Colophon.colophon
  48. })
  49. // page () {
  50. // }
  51. },
  52. watch: {
  53. $route (n, o) {
  54. console.log('static route changed', n, o)
  55. this.uuid = n.name
  56. if (this.colophon && this.colophon.length > 0) {
  57. this.setPage()
  58. }
  59. },
  60. colophon (n, o) {
  61. this.setPage()
  62. }
  63. },
  64. beforeCreate () {
  65. },
  66. created () {
  67. if (!this.colophon.length) {
  68. this.getColophon()
  69. }
  70. console.log('Static created', this.$route)
  71. this.uuid = this.$route.name
  72. if (this.colophon && this.colophon.length > 0) {
  73. this.setPage()
  74. }
  75. },
  76. methods: {
  77. ...mapActions({
  78. getColophon: 'Colophon/getColophon'
  79. }),
  80. setPage () {
  81. for (let i = 0; i < this.colophon.length; i++) {
  82. if (this.colophon[i].uuid === this.uuid) {
  83. this.page = this.colophon[i]
  84. }
  85. }
  86. this.parseContentImages()
  87. this.parseContentTOC()
  88. },
  89. parseContentImages () {
  90. console.log('parseContentImages')
  91. this.page.tei_parsed = this.page.tei.replace(/src="\/gdp\/static\/images\/(\w+)\.jpg"/g, `src="${window.apipath}/gdp/static/images/$1.jpg"`)
  92. // console.log(this.page.tei_parsed)
  93. },
  94. parseContentTOC () {
  95. let match = this.page.tei_parsed.match(/<h1[^>]*>[^<]+<\/h1>/g)
  96. console.log('match', match)
  97. match.forEach((element, index) => {
  98. console.log(element, index)
  99. // let elmt = element.replace(/<h1([^>]*)>([^<]+)<\/h1>/, `<h1 id="toc-${index}"$1>$2</h1>`)
  100. let elmtmatch = element.match(/(<h1([^>]*)>)([^<]+)<\/h1>/)
  101. let elmt = element.replace(elmtmatch[1], `<h1 id="toc-${index}"${elmtmatch[2]}>`)
  102. this.page.tei_parsed = this.page.tei_parsed.replace(element, elmt)
  103. this.toc.push({
  104. title: elmtmatch[3],
  105. hash: `toc-${index}`
  106. })
  107. })
  108. },
  109. onclickTOC (e) {
  110. console.log('onClickTOC', e, e.target.hash)
  111. this.reftoscrollto = e.target.hash
  112. }
  113. },
  114. metaInfo () {
  115. return {
  116. title: `Static`
  117. }
  118. }
  119. }
  120. </script>
  121. <style lang="scss" scoped>
  122. </style>