From 955ab11922d433daa4c501f32099629483cadab2 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Mon, 9 Apr 2018 11:36:25 +0200 Subject: [PATCH] [doc] Use the rule names for the search index, include language This provides better user experience for the search box on the documentation page. The search results show now the rule name, the language and the ruleset name. --- docs/search.json | 17 +++++++++++++++++ .../sourceforge/pmd/docs/RuleDocGenerator.java | 5 ++++- pmd-doc/src/test/resources/expected/sample.md | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/docs/search.json b/docs/search.json index a7f7dd0fe1..3a9de06912 100644 --- a/docs/search.json +++ b/docs/search.json @@ -7,6 +7,20 @@ search: exclude [ {% for page in site.pages %} {% unless page.search == "exclude" %} + +{% if page.permalink contains "pmd_rules_" and page.keywords %} +{% assign rules = page.keywords | split: ", " %} +{% for rule in rules %} +{ +"title": "{{ rule | escape }} ({{page.language}}, {{page.title}})", +"tags": "{{ page.tags }}", +"keywords": "{{rule}}", +"url": "{{ page.url | remove: "/"}}#{{ rule | downcase }}", +"summary": "{{page.summary | strip }}" +} +{% unless forloop.last %},{% endunless %} +{% endfor %} +{% else %} { "title": "{{ page.title | escape }}", "tags": "{{ page.tags }}", @@ -14,6 +28,9 @@ search: exclude "url": "{{ page.url | remove: "/"}}", "summary": "{{page.summary | strip }}" } +{% endif %} + + {% unless forloop.last and site.posts.size < 1 %},{% endunless %} {% endunless %} {% endfor %} diff --git a/pmd-doc/src/main/java/net/sourceforge/pmd/docs/RuleDocGenerator.java b/pmd-doc/src/main/java/net/sourceforge/pmd/docs/RuleDocGenerator.java index c333fcbb27..228d742496 100644 --- a/pmd-doc/src/main/java/net/sourceforge/pmd/docs/RuleDocGenerator.java +++ b/pmd-doc/src/main/java/net/sourceforge/pmd/docs/RuleDocGenerator.java @@ -314,7 +314,9 @@ public class RuleDocGenerator { */ private void generateRuleSetIndex(Map> rulesets) throws IOException { for (Map.Entry> entry : rulesets.entrySet()) { - String languageTersename = entry.getKey().getTerseName(); + Language language = entry.getKey(); + String languageTersename = language.getTerseName(); + String languageName = language.getName(); for (RuleSet ruleset : entry.getValue()) { String rulesetFilename = RuleSetUtils.getRuleSetFilename(ruleset); String filename = RULESET_INDEX_FILENAME_PATTERN @@ -336,6 +338,7 @@ public class RuleDocGenerator { lines.add("sidebaractiveurl: /" + LANGUAGE_INDEX_PERMALINK_PATTERN.replace("${language.tersename}", languageTersename)); lines.add("editmepath: ../" + getRuleSetSourceFilepath(ruleset)); lines.add("keywords: " + getRuleSetKeywords(ruleset)); + lines.add("language: " + languageName); lines.add("---"); for (Rule rule : getSortedRules(ruleset)) { diff --git a/pmd-doc/src/test/resources/expected/sample.md b/pmd-doc/src/test/resources/expected/sample.md index c2199072fc..620c7ccd28 100644 --- a/pmd-doc/src/test/resources/expected/sample.md +++ b/pmd-doc/src/test/resources/expected/sample.md @@ -6,6 +6,7 @@ folder: pmd/rules/java sidebaractiveurl: /pmd_rules_java.html editmepath: ../rulesets/ruledoctest/sample.xml keywords: Sample, OverrideBothEqualsAndHashcode, JumbledIncrementer, DeprecatedSample, RenamedRule, MovedRule +language: Java --- ## DeprecatedSample