cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblot...@apache.org
Subject docs commit: CB-10739 Reverse-engineering GitHub's slugifying function.
Date Thu, 03 Mar 2016 23:20:10 GMT
Repository: cordova-docs
Updated Branches:
  refs/heads/master c378b0cb6 -> 72c439e6c


CB-10739 Reverse-engineering GitHub's slugifying function.


Project: http://git-wip-us.apache.org/repos/asf/cordova-docs/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-docs/commit/72c439e6
Tree: http://git-wip-us.apache.org/repos/asf/cordova-docs/tree/72c439e6
Diff: http://git-wip-us.apache.org/repos/asf/cordova-docs/diff/72c439e6

Branch: refs/heads/master
Commit: 72c439e6c3280470bd87059532a5ea553f6fe1c4
Parents: c378b0c
Author: Dmitry Blotsky <dmitry.blotsky@gmail.com>
Authored: Wed Mar 2 15:13:05 2016 -0800
Committer: Dmitry Blotsky <dmitry.blotsky@gmail.com>
Committed: Thu Mar 3 15:19:45 2016 -0800

----------------------------------------------------------------------
 www/static/js/docs.js | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/72c439e6/www/static/js/docs.js
----------------------------------------------------------------------
diff --git a/www/static/js/docs.js b/www/static/js/docs.js
index c2221cc..8a11442 100644
--- a/www/static/js/docs.js
+++ b/www/static/js/docs.js
@@ -17,19 +17,25 @@
 
 $(document).ready(function () {
 
-    function slugify(text) {
+    function slugifyLikeGitHub(originalText) {
+
+        var text = originalText;
+
+        // convert to lowercase
         text = text.toLowerCase();
 
-        // replace unaccepted characters with spaces
+        // replace spaces with dashes
+        text = text.replace(/ /g, '-');
+
+        // remove unaccepted characters
         // NOTE:
-        //      a better regex would have been /[^\d\s\w]/ug, but the 'u' flag
+        //      a better regex would have been /[^\d\s\w-_]/ug, but the 'u' flag
         //      (Unicode) is not supported in some browsers, and we support
         //      many languages that use Unicode characters
-        text = text.replace(/[\[\]\(\)\=\+\?\.\,]/g, ' ');
+        text = text.replace(/[\[\]\(\)\=\+\?\!\.\,\{\}\\\/\>\<]/g, '');
 
-        // trim whitespace and replace runs of whitespace with single dashes
+        // trim remaining whitespace
         text = text.trim();
-        text = text.replace(/ +/g, '-');
 
         return text;
     }
@@ -40,7 +46,7 @@ $(document).ready(function () {
         } else if (heading.name) {
             return heading.name;
         } else {
-            return slugify(heading.innerText);
+            return slugifyLikeGitHub(heading.innerText);
         }
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message