index.vue 1.5 KB
Newer Older
1
<script>
2
/* eslint-disable vue/no-v-html */
3 4
import $ from 'jquery';
import '~/behaviors/markdown/render_gfm';
5
import { GlLink, GlLoadingIcon } from '@gitlab/ui';
6
import { handleLocationHash } from '~/lib/utils/common_utils';
7
import readmeQuery from '../../queries/readme.query.graphql';
8 9 10 11

export default {
  apollo: {
    readme: {
12
      query: readmeQuery,
13 14
      variables() {
        return {
15
          url: this.blob.webPath,
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
        };
      },
      loadingKey: 'loading',
    },
  },
  components: {
    GlLink,
    GlLoadingIcon,
  },
  props: {
    blob: {
      type: Object,
      required: true,
    },
  },
  data() {
    return {
      readme: null,
      loading: 0,
    };
  },
37 38 39 40
  watch: {
    readme(newVal) {
      if (newVal) {
        this.$nextTick(() => {
41
          handleLocationHash();
42 43 44 45 46
          $(this.$refs.readme).renderGFM();
        });
      }
    },
  },
47 48 49 50
};
</script>

<template>
51
  <article class="file-holder limited-width-container readme-holder">
52 53 54
    <div class="js-file-title file-title-flex-parent">
      <div class="file-header-content">
        <i aria-hidden="true" class="fa fa-file-text-o fa-fw"></i>
55
        <gl-link :href="blob.webPath">
56 57 58
          <strong>{{ blob.name }}</strong>
        </gl-link>
      </div>
59
    </div>
60
    <div class="blob-viewer" data-qa-selector="blob_viewer_content">
61
      <gl-loading-icon v-if="loading > 0" size="md" color="dark" class="my-4 mx-auto" />
62
      <div v-else-if="readme" ref="readme" v-html="readme.html"></div>
63 64 65
    </div>
  </article>
</template>