summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/vue_shared/components/content_viewer/lib/viewer_utils.js
blob: f2d6e8c5b4b40ae47acc9e25d9c003078f3c4af8 (plain)
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
const viewers = {
  image: {
    id: 'image',
  },
  markdown: {
    id: 'markdown',
    previewTitle: 'Preview Markdown',
  },
};

const fileNameViewers = {};
const fileExtensionViewers = {
  jpg: 'image',
  jpeg: 'image',
  gif: 'image',
  png: 'image',
  md: 'markdown',
  markdown: 'markdown',
};

export function viewerInformationForPath(path) {
  if (!path) return null;
  const name = path.split('/').pop();
  const viewerName =
    fileNameViewers[name] || fileExtensionViewers[name ? name.split('.').pop() : ''] || '';

  return viewers[viewerName];
}

export default viewers;