debian-mirror-gitlab/app/assets/javascripts/repository/utils/readme.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

32 lines
623 B
JavaScript
Raw Normal View History

2020-03-13 15:44:24 +05:30
const FILENAMES = ['index', 'readme'];
2019-12-26 22:10:19 +05:30
2020-03-13 15:44:24 +05:30
const MARKUP_EXTENSIONS = [
'ad',
'adoc',
'asciidoc',
'creole',
'markdown',
'md',
'mdown',
'mediawiki',
'mkd',
'mkdn',
'org',
'rdoc',
'rst',
'textile',
'wiki',
];
2019-12-26 22:10:19 +05:30
2021-03-08 18:12:59 +05:30
const isRichReadme = (file) => {
2020-03-13 15:44:24 +05:30
const re = new RegExp(`^(${FILENAMES.join('|')})\\.(${MARKUP_EXTENSIONS.join('|')})$`, 'i');
return re.test(file.name);
};
2019-12-26 22:10:19 +05:30
2021-03-08 18:12:59 +05:30
const isPlainReadme = (file) => {
2020-03-13 15:44:24 +05:30
const re = new RegExp(`^(${FILENAMES.join('|')})(\\.txt)?$`, 'i');
return re.test(file.name);
2019-12-26 22:10:19 +05:30
};
2020-03-13 15:44:24 +05:30
2021-03-08 18:12:59 +05:30
export const readmeFile = (blobs) => blobs.find(isRichReadme) || blobs.find(isPlainReadme);