From 556bca3099d5e8133e6e1b48a340a56adfbfc67e Mon Sep 17 00:00:00 2001 From: Asher Baker Date: Fri, 25 Jul 2014 06:43:25 -0700 Subject: [PATCH] Order readme files based on how well we can get the markup right. Summary: Handling readmes with no extension is a bit of a hack, but seemed like a small cost. The Big Win here is that you can commit README.remarkup and README.md and have both Phabricator and GitHub render __with__ //all// ##the## ~~pretty~~ **markup**. Test Plan: Looked at some readme files. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: epriestley, Korvin Differential Revision: https://secure.phabricator.com/D10047 --- .../DiffusionReadmeQueryConduitAPIMethod.php | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/applications/diffusion/conduit/DiffusionReadmeQueryConduitAPIMethod.php b/src/applications/diffusion/conduit/DiffusionReadmeQueryConduitAPIMethod.php index a34c58dc68..2589bb2452 100644 --- a/src/applications/diffusion/conduit/DiffusionReadmeQueryConduitAPIMethod.php +++ b/src/applications/diffusion/conduit/DiffusionReadmeQueryConduitAPIMethod.php @@ -32,6 +32,7 @@ final class DiffusionReadmeQueryConduitAPIMethod $paths[] = DiffusionRepositoryPath::newFromDictionary($dict); } + $best = -1; $readme = ''; foreach ($paths as $result_path) { $file_type = $result_path->getFileType(); @@ -41,11 +42,35 @@ final class DiffusionReadmeQueryConduitAPIMethod continue; } - $path = $result_path->getPath(); + $path = strtolower($result_path->getPath()); - if (preg_match('/^readme(|\.txt|\.remarkup|\.rainbow|\.md)$/i', $path)) { + if ($path === 'readme') { + $path .= '.txt'; + } + + if (strncmp($path, 'readme.', 7) !== 0) { + continue; + } + + $priority = 0; + switch (substr($path, 7)) { + case 'remarkup': + $priority = 100; + break; + case 'rainbow': + $priority = 90; + break; + case 'md': + $priority = 50; + break; + case 'txt': + $priority = 10; + break; + } + + if ($priority > $best) { + $best = $priority; $readme = $result_path; - break; } }