gitlab-org--gitlab-foss/app/assets/javascripts/repository/utils
2020-10-08 12:08:31 +00:00
..
commit.js Add latest changes from gitlab-org/gitlab@master 2020-08-22 00:10:21 +00:00
dom.js Add latest changes from gitlab-org/gitlab@master 2020-02-10 15:08:54 +00:00
readme.js Add latest changes from gitlab-org/gitlab@master 2020-08-22 00:10:21 +00:00
title.js Add latest changes from gitlab-org/gitlab@master 2020-03-18 15:09:45 +00:00

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);
};

export const readmeFile = blobs => blobs.find(isRichReadme) || blobs.find(isPlainReadme);