debian-mirror-gitlab/app/assets/javascripts/repository/utils
2020-03-09 13:42:32 +05:30
..
commit.js New upstream version 12.6.1 2020-01-01 13:55:28 +05:30
dom.js New upstream version 12.8.5 2020-03-09 13:42:32 +05:30
icon.js New upstream version 12.0.8 2019-09-04 21:01:54 +05:30
readme.js New upstream version 12.8.5 2020-03-09 13:42:32 +05:30
title.js New upstream version 12.8.5 2020-03-09 13:42:32 +05:30

const FILENAMES = ['index', 'readme'];

const MARKUP_EXTENSIONS = [
  'ad',
  'adoc',
  'asciidoc',
  'creole',
  'markdown',
  'md',
  'mdown',
  'mediawiki',
  'mkd',
  'mkdn',
  'org',
  'rdoc',
  'rst',
  'textile',
  'wiki',
];

const isRichReadme = file => {
  const re = new RegExp(`^(${FILENAMES.join('|')})\\.(${MARKUP_EXTENSIONS.join('|')})$`, 'i');
  return re.test(file.name);
};

const isPlainReadme = file => {
  const re = new RegExp(`^(${FILENAMES.join('|')})(\\.txt)?$`, 'i');
  return re.test(file.name);
};

// eslint-disable-next-line import/prefer-default-export
export const readmeFile = blobs => blobs.find(isRichReadme) || blobs.find(isPlainReadme);