debian-mirror-gitlab/app/assets/javascripts/repository/utils
2020-01-01 13:55:28 +05:30
..
commit.js New upstream version 12.6.1 2020-01-01 13:55:28 +05:30
dom.js New upstream version 12.6.1 2020-01-01 13:55:28 +05:30
icon.js New upstream version 12.0.8 2019-09-04 21:01:54 +05:30
readme.js New upstream version 12.5.4 2019-12-26 22:10:19 +05:30
title.js New upstream version 12.5.4 2019-12-26 22:10:19 +05:30

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