gitlab-org--gitlab-foss/app/assets/javascripts/repository/utils
2019-11-25 18:06:04 +00:00
..
commit.js Add latest changes from gitlab-org/gitlab@master 2019-11-25 12:06:13 +00:00
dom.js Add latest changes from gitlab-org/gitlab@master 2019-11-25 18:06:04 +00:00
icon.js
readme.js Add latest changes from gitlab-org/gitlab@master 2019-11-14 12:06:30 +00:00
title.js Add latest changes from gitlab-org/gitlab@master 2019-11-12 18:06:57 +00:00

const MARKDOWN_EXTENSIONS = ['mdown', 'mkd', 'mkdn', 'md', 'markdown'];
const ASCIIDOC_EXTENSIONS = ['adoc', 'ad', 'asciidoc'];
const OTHER_EXTENSIONS = ['textile', 'rdoc', 'org', 'creole', 'wiki', 'mediawiki', 'rst'];
const EXTENSIONS = [...MARKDOWN_EXTENSIONS, ...ASCIIDOC_EXTENSIONS, ...OTHER_EXTENSIONS];
const PLAIN_FILENAMES = ['readme', 'index'];
const FILE_REGEXP = new RegExp(
  `^(${PLAIN_FILENAMES.join('|')})(.(${EXTENSIONS.join('|')}))?$`,
  'i',
);
const PLAIN_FILE_REGEXP = new RegExp(`^(${PLAIN_FILENAMES.join('|')})`, 'i');
const EXTENSIONS_REGEXP = new RegExp(`.(${EXTENSIONS.join('|')})$`, 'i');

// eslint-disable-next-line import/prefer-default-export
export const readmeFile = blobs => {
  const readMeFiles = blobs.filter(f => f.name.search(FILE_REGEXP) !== -1);

  const previewableReadme = readMeFiles.find(f => f.name.search(EXTENSIONS_REGEXP) !== -1);
  const plainReadme = readMeFiles.find(f => f.name.search(PLAIN_FILE_REGEXP) !== -1);

  return previewableReadme || plainReadme;
};