Page.vue 1.08 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<template>
  <div class="row">
    <section v-html="content"></section>
  </div>
</template>

<script>
import PageMixin from "../PageMixin";

export default {
  mixins: [PageMixin],
  data() {
    return {
      rawContent: null,
      marked: null
    };
  },
  computed: {
    page() {
      return this.$router.currentRoute.name;
    },
    content() {
      if (this.rawContent) {
        return this.marked(this.rawContent);
      }
      return null;
    }
  },
  async created() {
    let self = this;
    this.marked = (await import("marked")).default;
    await self.render();
  },
  methods: {
    async render() {
      let language = this.$language.current;
      let fallback = "en_US";
      let content;
      try {
        content = await import(
          `raw-loader!../pages/${this.page}/${language}.md`
        );
      } catch {
        content = await import(
          `raw-loader!../pages/${this.page}/${fallback}.md`
        );
      }
      this.rawContent = content.default;
    }
  },
  watch: {
    async "$language.current"() {
      await this.render();
    }
  }
};
</script>