summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/repository
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-10 15:07:47 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-10 15:07:47 +0000
commit8b1228b0d409d7751f01d9fb72ebfbbf62399486 (patch)
tree1b4126fe48d7666a90c0d7ee26230cf8379b6410 /app/assets/javascripts/repository
parent96b0c1245c93585a8b0fe23e22306d32ff4e4905 (diff)
downloadgitlab-ce-8b1228b0d409d7751f01d9fb72ebfbbf62399486.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/repository')
-rw-r--r--app/assets/javascripts/repository/utils/readme.js45
1 files changed, 28 insertions, 17 deletions
diff --git a/app/assets/javascripts/repository/utils/readme.js b/app/assets/javascripts/repository/utils/readme.js
index e43b2bdc33a..ef4162f4463 100644
--- a/app/assets/javascripts/repository/utils/readme.js
+++ b/app/assets/javascripts/repository/utils/readme.js
@@ -1,21 +1,32 @@
-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');
+const FILENAMES = ['index', 'readme'];
-// eslint-disable-next-line import/prefer-default-export
-export const readmeFile = blobs => {
- const readMeFiles = blobs.filter(f => f.name.search(FILE_REGEXP) !== -1);
+const MARKUP_EXTENSIONS = [
+ 'ad',
+ 'adoc',
+ 'asciidoc',
+ 'creole',
+ 'markdown',
+ 'md',
+ 'mdown',
+ 'mediawiki',
+ 'mkd',
+ 'mkdn',
+ 'org',
+ 'rdoc',
+ 'rst',
+ 'textile',
+ 'wiki',
+];
- const previewableReadme = readMeFiles.find(f => f.name.search(EXTENSIONS_REGEXP) !== -1);
- const plainReadme = readMeFiles.find(f => f.name.search(PLAIN_FILE_REGEXP) !== -1);
+const isRichReadme = file => {
+ const re = new RegExp(`^(${FILENAMES.join('|')})\\.(${MARKUP_EXTENSIONS.join('|')})$`, 'i');
+ return re.test(file.name);
+};
- return previewableReadme || plainReadme;
+const isPlainReadme = file => {
+ const re = new RegExp(`^(${FILENAMES.join('|')})$`, 'i');
+ return re.test(file.name);
};
+
+// eslint-disable-next-line import/prefer-default-export
+export const readmeFile = blobs => blobs.find(isRichReadme) || blobs.find(isPlainReadme);