SOLR-11540: eliminate the need for explicitly definied page-shortname and/or page-permalink attributes in our asciidoc source files

This commit is contained in:
Chris Hostetter 2017-10-25 09:36:41 -07:00
parent 0b3c3000e0
commit 8a138908c5
6 changed files with 33 additions and 20 deletions

View File

@ -4,7 +4,7 @@
<meta name="description" content="{% if page.description %}{{ page.description | strip_html | strip_newlines | truncate: 160 }}{% endif %}">
<meta name="keywords" content="{{page.tags}}{% if page.tags %}, {% endif %} {{page.keywords}}">
{% comment %}NOTE: explicitly using the GUIDE version here (not solr) {% endcomment %}
<title>{% if page.shortname != "index" %}{{ page.title }} | {% endif %}{{ site.site_title }} {{ site.solr-attributes.solr-guide-version}}</title>
<title>{% if page_id != "index" %}{{ page.title }} | {% endif %}{{ site.site_title }} {{ site.solr-attributes.solr-guide-version}}</title>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<!--<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">-->

View File

@ -56,10 +56,10 @@
<!-- set the 'active' class on the current page and ancestors -->
<!-- this highlights the active parent class in the navgoco sidebar. this is critical so that the parent expands when you're viewing a page. This must appear below the sidebar code above. Otherwise, if placed inside customscripts.js, the script runs before the sidebar code runs and the class never gets inserted.-->
<script>$("#mysidebar a[href='{{ page.shortname }}.html']").parents('li').toggleClass("active", true);</script>
<script>$("#mysidebar a[href='{{ page_id }}.html']").parents('li').toggleClass("active", true);</script>
<!-- set the 'current' class on the current page and 'current-tree' on the current page + it's ancestors -->
<!-- this can let us do css highlighting of the current page in the sidebar even if/when the user clicks around in the sidebar causing other sidebar elements to be 'active' -->
<script>
$("#mysidebar a[href='{{ page.shortname }}.html']").parent('li').toggleClass("current", true);
$("#mysidebar a[href='{{ page.shortname }}.html']").parents('li').toggleClass("current-tree", true);
$("#mysidebar a[href='{{ page_id }}.html']").parent('li').toggleClass("current", true);
$("#mysidebar a[href='{{ page_id }}.html']").parents('li').toggleClass("current-tree", true);
</script>

View File

@ -1,4 +1,6 @@
<!DOCTYPE html>
{% comment %}NOTE: page_id is also definied in page.html{% endcomment %}
{% assign page_id = page.url | split: '/' | last | remove: '.html' %}
<head>
{% include head.html %}
<script>
@ -31,7 +33,7 @@
</script>
</head>
<body class="{{ site.solr-attributes.solr-guide-draft-status }}" id="{{ page.shortname }}">
<body class="{{ site.solr-attributes.solr-guide-draft-status }}" id="{{ page_id }}">
{% include topnav.html %}
<!-- Page Content -->
<div class="container">

View File

@ -1,7 +1,8 @@
---
layout: default
---
{% comment %}NOTE: page_id is also definied in default.html{% endcomment %}
{% assign page_id = page.url | split: '/' | last | remove: '.html' %}
<div class="post-header">
<h1 class="post-title-main">{{ page.title }}</h1>
</div>
@ -53,7 +54,7 @@ layout: default
</div>
<!-- Adds nav links on each page -->
{% assign scrollnav = site.data.scrollnav[page.shortname] %}
{% assign scrollnav = site.data.scrollnav[page_id] %}
{% if scrollnav %}
<div class="scrollnav">
{% if scrollnav.prev %}
@ -73,10 +74,10 @@ layout: default
<div style="font-size: 1.6em; color: #d9411e; padding-top: 30px;">Comments on this Page</div>
<div class="paragraph"><p>We welcome feedback on Solr documentation. However, we cannot provide application support via comments. If you need help, please send a message to the <a href="https://lucene.apache.org/solr/resources.html#community">Solr User mailing list</a>.</p></div>
</div>
<script type="text/javascript" src="https://comments.apache.org/show_comments.lua?site=solr-refguide&style=css/comments.css&page={{ page.shortname }}" async="true">
<script type="text/javascript" src="https://comments.apache.org/show_comments.lua?site=solr-refguide&style=css/comments.css&page={{ page_id }}" async="true">
</script>
<noscript>
<iframe width="100%" height="500" src="https://comments.apache.org/iframe.lua?site=solr-refguide&style=css/comments.css&page={{ page.shortname }}"></iframe>
<iframe width="100%" height="500" src="https://comments.apache.org/iframe.lua?site=solr-refguide&style=css/comments.css&page={{ page_id }}"></iframe>
</noscript>
{% include footer.html %}

View File

@ -3,7 +3,7 @@ layout: default_print
comments: true
---
<div class="post-header">
<h1 class="post-title-main" id="{{page.permalink | replace: '/', '' }}">{{ page.title }}</h1>
<h1 class="post-title-main">{{ page.title }}</h1>
</div>
<div class="post-content">

View File

@ -208,7 +208,7 @@ public class BuildNavAndPDFBody {
/** Simple struct for modeling the key metadata for dealing with page navigation */
public static final class Page {
public final File file;
public final String title;
public final String title; // NOTE: has html escape codes in it
public final String shortname;
public final String permalink;
public final List<String> kidShortnames;
@ -218,23 +218,33 @@ public class BuildNavAndPDFBody {
public final List<Page> kids;
private final List<Page> mutableKids;
public Page(File file, DocumentHeader header) {
if (! file.getName().endsWith(".adoc")) {
throw new RuntimeException(file + " has does not end in '.adoc' - this code can't be used");
}
this.file = file;
this.title = header.getDocumentTitle().getMain();
this.shortname = file.getName().replaceAll("\\.adoc$","");
this.permalink = this.shortname + ".html";
// TODO: do error checking if attribute metadata we care about is missing
Map<String,Object> attrs = header.getAttributes();
this.shortname = (String) attrs.get("page-shortname");
this.permalink = (String) attrs.get("page-permalink");
// TODO: SOLR-11531: we should eliminate these attributes and not depend on them in jekyll, ...
// ...but for now at least be sure they are consistent with the filename
if (! file.getName().equals(shortname + ".adoc") ) {
throw new RuntimeException(file + " has a mismatched shortname: " + shortname);
// TODO: SOLR-11541: we should eliminate these attributes
// ...but for now at least be sure they are consistent
if (attrs.containsKey("page-shortname")) {
String explicit = (String) attrs.get("page-shortname");
if (! shortname.equals(explicit)) {
throw new RuntimeException(file + " ("+shortname+") has a mismatched page-shortname: " + explicit);
}
}
if (attrs.containsKey("page-permalink")) {
String explicit = (String) attrs.get("page-permalink");
if (! permalink.equals(explicit)) {
throw new RuntimeException(file + "("+permalink+") has a mismatched permalink: " + explicit);
}
if (! permalink.equals(shortname + ".html") ) {
throw new RuntimeException(file + " has a mismatched permalink: " + permalink);
}
if (attrs.containsKey("page-children")) {
String kidsString = ((String) attrs.get("page-children")).trim();