debian-mirror-gitlab/app/assets/javascripts/repository/utils
2023-05-08 21:46:49 +05:30
..
commit.js New upstream version 15.4.2+ds1 2022-10-11 01:57:18 +05:30
dom.js New upstream version 13.8.5+ds1 2021-03-08 18:12:59 +05:30
readme.js New upstream version 13.8.5+ds1 2021-03-08 18:12:59 +05:30
ref_switcher_utils.js New upstream version 15.9.7+ds1 2023-05-08 21:46:49 +05:30
title.js New upstream version 12.10.0 2020-04-22 19:07:51 +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);
};

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