mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-06-07 16:13:55 +02:00
fix(#109): fix README redirection in case of multi-matches
This commit is contained in:
+30
-9
@@ -1279,18 +1279,39 @@ angular
|
|||||||
(res) => {
|
(res) => {
|
||||||
$scope.files = res.data;
|
$scope.files = res.data;
|
||||||
if ($scope.paths.length == 0 || $scope.paths[0] == "") {
|
if ($scope.paths.length == 0 || $scope.paths[0] == "") {
|
||||||
for (let file in $scope.files) {
|
// redirect to readme
|
||||||
// redirect to readme
|
const readmeCandidates = {};
|
||||||
|
for (const file in $scope.files) {
|
||||||
if (file.toLowerCase().indexOf("readme") > -1) {
|
if (file.toLowerCase().indexOf("readme") > -1) {
|
||||||
let uri = $location.url();
|
readmeCandidates[file.toLowerCase()] = file;
|
||||||
if (uri[uri.length - 1] != "/") {
|
|
||||||
uri += "/";
|
|
||||||
}
|
|
||||||
|
|
||||||
// redirect to readme
|
|
||||||
$location.url(uri + file);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const readmePriority = [
|
||||||
|
"readme.md",
|
||||||
|
"readme.txt",
|
||||||
|
"readme.org",
|
||||||
|
"readme.1st",
|
||||||
|
"readme",
|
||||||
|
];
|
||||||
|
let best_match = null;
|
||||||
|
for (const p of readmePriority) {
|
||||||
|
if (readmeCandidates[p]) {
|
||||||
|
best_match = p;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!best_match && Object.keys(readmeCandidates).length > 0)
|
||||||
|
best_match = Object.keys(readmeCandidates)[0];
|
||||||
|
if (best_match) {
|
||||||
|
let uri = $location.url();
|
||||||
|
if (uri[uri.length - 1] != "/") {
|
||||||
|
uri += "/";
|
||||||
|
}
|
||||||
|
|
||||||
|
// redirect to readme
|
||||||
|
$location.url(uri + readmeCandidates[best_match]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (callback) {
|
if (callback) {
|
||||||
return callback();
|
return callback();
|
||||||
|
|||||||
Reference in New Issue
Block a user