diff --git a/.github/deploy.sh b/.github/deploy.sh index 34225a540290..5a59f94ec918 100644 --- a/.github/deploy.sh +++ b/.github/deploy.sh @@ -8,6 +8,7 @@ rm -rf out/master/ || exit 0 echo "Making the docs for master" mkdir out/master/ cp util/gh-pages/index.html out/master +cp util/gh-pages/script.js out/master cp util/gh-pages/lints.json out/master if [[ -n $TAG_NAME ]]; then diff --git a/util/gh-pages/index.html b/util/gh-pages/index.html index 97c974003c62..1171da3f4e52 100644 --- a/util/gh-pages/index.html +++ b/util/gh-pages/index.html @@ -94,6 +94,29 @@ @media (min-width: 992px) { .search-control { margin-top: 0; + float: right; + } + } + + @media (min-width: 405px) { + #upper-filters { + display: flex; + } + } + + @media (max-width: 430px) { + /* Turn the version filter list to the left */ + #version-filter-selector { + right: 0; + left: auto; + } + } + + @media (max-width: 412px) { + #upper-filters, + .panel-body .search-control { + padding-right: 8px; + padding-left: 8px; } } @@ -244,7 +267,7 @@ cursor: pointer; } - .theme-choice>li:hover { + .theme-choice > li:hover { background: var(--theme-hover); } @@ -273,23 +296,44 @@ border: 1px solid var(--theme-popup-border); } - #filter-label, #filter-clear { + #version-filter-selector .checkbox { + display: flex; + } + + #version-filter { + min-width: available; + } + + #version-filter li label { + padding-right: 0; + width: 35%; + } + + .version-filter-input { + height: 60%; + width: 30%; + text-align: center; + border: none; + border-bottom: 1px solid #000000; + } + + #filter-label, .filter-clear { background: var(--searchbar-bg); color: var(--searchbar-fg); border-color: var(--theme-popup-border); filter: brightness(95%); } - #filter-label:hover, #filter-clear:hover { + #filter-label:hover, .filter-clear:hover { filter: brightness(90%); } - #filter-input { + .filter-input { background: var(--searchbar-bg); color: var(--searchbar-fg); border-color: var(--theme-popup-border); } - #filter-input::-webkit-input-placeholder, - #filter-input::-moz-placeholder { + .filter-input::-webkit-input-placeholder, + .filter-input::-moz-placeholder { color: var(--searchbar-fg); opacity: 30%; } @@ -338,7 +382,7 @@

Clippy Lints

-
+
+
+
+ + +
+
+
-
+
- - + + - @@ -406,7 +484,7 @@

Clippy Lints

-
+

@@ -462,295 +540,6 @@

- + diff --git a/util/gh-pages/script.js b/util/gh-pages/script.js new file mode 100644 index 000000000000..c3250afdea20 --- /dev/null +++ b/util/gh-pages/script.js @@ -0,0 +1,350 @@ +(function () { + var md = window.markdownit({ + html: true, + linkify: true, + typographer: true, + highlight: function (str, lang) { + if (lang && hljs.getLanguage(lang)) { + try { + return '
' +
+                        hljs.highlight(lang, str, true).value +
+                        '
'; + } catch (__) {} + } + + return '
' + md.utils.escapeHtml(str) + '
'; + } + }); + + function scrollToLint(lintId) { + var target = document.getElementById(lintId); + if (!target) { + return; + } + target.scrollIntoView(); + } + + function scrollToLintByURL($scope) { + var removeListener = $scope.$on('ngRepeatFinished', function(ngRepeatFinishedEvent) { + scrollToLint(window.location.hash.slice(1)); + removeListener(); + }); + } + + function selectGroup($scope, selectedGroup) { + var groups = $scope.groups; + for (var group in groups) { + if (groups.hasOwnProperty(group)) { + if (group === selectedGroup) { + groups[group] = true; + } else { + groups[group] = false; + } + } + } + } + + angular.module("clippy", []) + .filter('markdown', function ($sce) { + return function (text) { + return $sce.trustAsHtml( + md.render(text || '') + // Oh deer, what a hack :O + .replace(' minorVersion) { return false; } + break; + default: + return true + } + } + } + + return true; + } + + $scope.byGroups = function (lint) { + return $scope.groups[lint.group]; + }; + + $scope.bySearch = function (lint, index, array) { + let searchStr = $scope.search; + // It can be `null` I haven't missed this value + if (searchStr == null || searchStr.length < 3) { + return true; + } + searchStr = searchStr.toLowerCase(); + + // Search by id + if (lint.id.indexOf(searchStr.replace("-", "_")) !== -1) { + return true; + } + + // Search the description + // The use of `for`-loops instead of `foreach` enables us to return early + let terms = searchStr.split(" "); + let docsLowerCase = lint.docs.toLowerCase(); + for (index = 0; index < terms.length; index++) { + // This is more likely and will therefor be checked first + if (docsLowerCase.indexOf(terms[index]) !== -1) { + continue; + } + + if (lint.id.indexOf(terms[index]) !== -1) { + continue; + } + + return false; + } + + return true; + } + + // Get data + $scope.open = {}; + $scope.loading = true; + // This will be used to jump into the source code of the version that this documentation is for. + $scope.docVersion = window.location.pathname.split('/')[2] || "master"; + + if (window.location.hash.length > 1) { + $scope.search = window.location.hash.slice(1); + $scope.open[window.location.hash.slice(1)] = true; + scrollToLintByURL($scope); + } + + $http.get('./lints.json') + .success(function (data) { + $scope.data = data; + $scope.loading = false; + + var selectedGroup = getQueryVariable("sel"); + if (selectedGroup) { + selectGroup($scope, selectedGroup.toLowerCase()); + } + + scrollToLintByURL($scope); + + setTimeout(function () { + var el = document.getElementById('filter-input'); + if (el) { el.focus() } + }, 0); + }) + .error(function (data) { + $scope.error = data; + $scope.loading = false; + }); + + window.addEventListener('hashchange', function () { + // trigger re-render + $timeout(function () { + $scope.levels = LEVEL_FILTERS_DEFAULT; + $scope.search = window.location.hash.slice(1); + $scope.open[window.location.hash.slice(1)] = true; + + scrollToLintByURL($scope); + }); + return true; + }, false); + }); +})(); + +function getQueryVariable(variable) { + var query = window.location.search.substring(1); + var vars = query.split('&'); + for (var i = 0; i < vars.length; i++) { + var pair = vars[i].split('='); + if (decodeURIComponent(pair[0]) == variable) { + return decodeURIComponent(pair[1]); + } + } +} + +function setTheme(theme, store) { + let enableHighlight = false; + let enableNight = false; + let enableAyu = false; + + if (theme == "ayu") { + enableAyu = true; + } else if (theme == "coal" || theme == "navy") { + enableNight = true; + } else if (theme == "rust") { + enableHighlight = true; + } else { + enableHighlight = true; + // this makes sure that an unknown theme request gets set to a known one + theme = "light"; + } + document.getElementsByTagName("body")[0].className = theme; + + document.getElementById("styleHighlight").disabled = !enableHighlight; + document.getElementById("styleNight").disabled = !enableNight; + document.getElementById("styleAyu").disabled = !enableAyu; + + if (store) { + try { + localStorage.setItem('clippy-lint-list-theme', theme); + } catch (e) { } + } +} + +// loading the theme after the initial load +setTheme(localStorage.getItem('clippy-lint-list-theme'), false);