sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject [1/4] sling-site git commit: Activate ToC using toc.js
Date Wed, 27 Sep 2017 12:20:53 GMT
Repository: sling-site
Updated Branches:
  refs/heads/master 148eadb81 -> 4807ce0c4


http://git-wip-us.apache.org/repos/asf/sling-site/blob/f7d38e20/src/main/jbake/assets/res/tocjs-1-1-2.js
----------------------------------------------------------------------
diff --git a/src/main/jbake/assets/res/tocjs-1-1-2.js b/src/main/jbake/assets/res/tocjs-1-1-2.js
new file mode 100644
index 0000000..6f8b43a
--- /dev/null
+++ b/src/main/jbake/assets/res/tocjs-1-1-2.js
@@ -0,0 +1,11 @@
+/**
+ * TocJS v1.1.2 (http://github.com/nghuuphuoc/tocjs)
+ *
+ * Generate a table of contents based on headings
+ *
+ * @author      http://twitter.com/nghuuphuoc
+ * @copyright   (c) 2013 - 2014 Nguyen Huu Phuoc
+ * @license     MIT
+ */
+
+!function(a){var b=function(c,d){this.$element=a(c),this.options=a.extend({},b.DEFAULT_OPTIONS,d),this.headings=[],this.$element.addClass(this.options.elementClass);var
e=this;a(this.options.selector).each(function(b,c){a(c).data("tagNumber",parseInt(c.tagName.substring(1))).data("index",1).data("numbering","1"),e.headings.push(c)}),this.headings.length>0&&this.render()};b.DEFAULT_OPTIONS={selector:"h1,
h2, h3, h4, h5, h6",elementClass:"toc",rootUlClass:"toc-ul-root",ulClass:"toc-ul",prefixLinkClass:"toc-link-",heading:null,indexingFormats:{}},b.prototype={constructor:b,render:function(){for(var
b={},c=this.headings,d=this.headings.length,e=0;d>e;e++){var f=a(c[e]).data("tagNumber");if(0==e)b[c[0].tagName]=a(c[0]);else{var
g=a(c[e-1]).data("tagNumber"),h=String(a(c[e-1]).data("numbering")).split(".");switch(!0){case
f==g:var i=a(c[e-1]).data("index")+1;a(c[e]).data("index",i),1==h.length?a(c[e]).data("numbering",parseInt(h[0])+1):(h.pop(),h.push(i),a(c[e]).data("numbering",h.join(".
 "))),b[c[e].tagName]=a(c[e]);break;case f>g:h.push("1"),a(c[e]).data("index",1).data("numbering",h.join(".")),b[c[e].tagName]=a(c[e]);break;case
g>f:var j=b[c[e].tagName],k=String(a(j).data("numbering")).split("."),i=a(j).data("index")+1;a(c[e]).data("index",i),1==k.length?a(c[e]).data("numbering",parseInt(k[0])+1):(k.pop(),k.push(i),a(c[e]).data("numbering",k.join("."))),b[c[e].tagName]=a(c[e])}}}var
l={},m=a("<ul/>").addClass(this.options.rootUlClass).addClass(this.options.ulClass).appendTo(this.$element);this.options.heading&&a("<li/>").addClass("toc-heading").wrapInner(a("<a/>").attr("href","#").html(this.options.heading)).appendTo(m);for(var
e=0;d>e;e++){var n=this.generateHeadingId(c[e]),o=String(a(c[e]).data("numbering")).split("."),p=a("<a/>").html(a(c[e]).text()).addClass(this.options.prefixLinkClass+o.length).attr("href","#"+n);if(a("<a/>").addClass("toc-anchor").html("#").attr("href","#"+n).hide().appendTo(c[e]),a(c[e]).on("mouseover",function(){a(this).find(".toc-anchor"
 ).show()}).on("mouseout",function(){a(this).find(".toc-anchor").hide()}),1==o.length)var
q=a("<li/>").wrapInner(p).appendTo(m);else{var r=o.pop(),s=o.join("."),t=l[s].find("ul"),u=t.length>0?t.get(0):a("<ul/>").addClass(this.options.ulClass).appendTo(l[s]),q=a("<li/>").wrapInner(p).appendTo(u);o.push(r)}l[o.join(".")]=q,this.prependIndexing(e,p)}},generateHeadingId:function(b){if(!a(b).attr("id")){for(var
c=a(b).text().toLowerCase().replace(/\s+|\/|\\/g,"-").replace(/á|à|ạ|ả|ã|ă|ắ|ằ|ặ|ẳ|ẵ|â|ấ|ầ|ậ|ẩ|ẫ|ä/g,"a").replace(/đ/g,"d").replace(/é|è|ẹ|ẻ|ẽ|ê|ế|ề|ệ|ể|ễ/g,"e").replace(/í|ì|ị|ỉ|ĩ/g,"i").replace(/ó|ò|ọ|ỏ|õ|ô|ố|ồ|ộ|ổ|ỗ|ơ|ớ|ờ|ợ|ở|ỡ/g,"o").replace(/ú|ù|ụ|ủ|ũ|ư|ứ|ừ|ự|ử|ữ/g,"u").replace(/ý|ỳ|ỵ|ỷ|ỹ/g,"y").replace(/[^a-z0-9-]/g,""),d=!0,e=0;d;)d=a("#"+c+(0==e?"":"-"+e)).length>0,d?e++:c+=0==e?"":"-"+e;return
a(b).attr("id",c),c}return a(b).attr("id")},prependIndexing:function(
 b,c){var d=this.headings[b],e=parseInt(a(d).data("tagNumber")),f=this.getIndexingFormat(e);if(null!=f){for(var
g=String(a(d).data("numbering")).split("."),h=g.length,i=[],j=0,k=0;h>k;k++)j=k+(e-h)+1,f=this.getIndexingFormat(j),f&&i.push(this.convertIndexing(g[k],f));if(i.length>0){var
l=i.join(". ")+". ";a(c).prepend(l),a(d).prepend(l)}}},getIndexingFormat:function(a){if("object"==typeof
this.options.indexingFormats)return this.options.indexingFormats["h"+a]?this.options.indexingFormats["h"+a]:null;if("string"==typeof
this.options.indexingFormats){if(-1!=["upperAlphabet","lowerAlphabet","number","upperRoman","lowerRoman"].indexOf(this.options.indexingFormats))return
this.options.indexingFormats;if(this.options.indexingFormats.length<a)return null;switch(this.options.indexingFormats[a-1]){case"1":case
1:return"number";case"A":return"upperAlphabet";case"a":return"lowerAlphabet";case"I":return"upperRoman";case"i":return"lowerRoman";default:return
null}}return null},convertIndexing:func
 tion(a,b){var c="abcdefghijklmnopqrstuvwxyz",d="ABCDEFGHIJKLMNOPQRSTUVWXYZ",e=c.length;switch(b){case"upperAlphabet":case"A":return
a>e?d[a%e-1]:d[a-1];case"lowerAlphabet":case"a":return a>e?c[a%e-1]:c[a-1];case"number":case"1":case
1:return a;case"upperRoman":case"I":return this.convertToRomanNumeral(a);case"lowerRoman":case"i":return
this.convertToRomanNumeral(a).toLowerCase();default:return"_"}},convertToRomanNumeral:function(a){if(!+a)return"";for(var
b=String(+a).split(""),c=["","C","CC","CCC","CD","D","DC","DCC","DCCC","CM","","X","XX","XXX","XL","L","LX","LXX","LXXX","XC","","I","II","III","IV","V","VI","VII","VIII","IX"],d="",e=3;e--;)d=(c[+b.pop()+10*e]||"")+d;return
Array(+b.join("")+1).join("M")+d}},a.fn.toc=function(c){return this.each(function(){var d=a(this),e=d.data("toc");e||d.data("toc",e=new
b(this,c))})},a.fn.toc.Constructor=b}(window.jQuery);
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/sling-site/blob/f7d38e20/src/main/jbake/content/index.md
----------------------------------------------------------------------
diff --git a/src/main/jbake/content/index.md b/src/main/jbake/content/index.md
index ff68b71..177e2d2 100644
--- a/src/main/jbake/content/index.md
+++ b/src/main/jbake/content/index.md
@@ -137,7 +137,7 @@ is expected that Sling also operates perfectly inside other OSGi frameworks
 such as [Equinox](http://www.eclipse.org/equinox) and [Knopflerfish](http://www.knopflerfish.org).
 
 
-<script src="/res/jquery.js" type="text/javascript"></script>
+<script src="/res/jquery-3.2.1.min.js" type="text/javascript"></script>
 <script type="text/javascript">
         $(document).ready(function() {
             $.get("/news.html", function(news) {

http://git-wip-us.apache.org/repos/asf/sling-site/blob/f7d38e20/src/main/jbake/templates/layout/main.tpl
----------------------------------------------------------------------
diff --git a/src/main/jbake/templates/layout/main.tpl b/src/main/jbake/templates/layout/main.tpl
index 523b1ac..5df7589 100644
--- a/src/main/jbake/templates/layout/main.tpl
+++ b/src/main/jbake/templates/layout/main.tpl
@@ -14,6 +14,7 @@ html(lang:'en'){
             	yield "${ content ? content.title : "<MISSING CONTENT OBJECT??>" }"
 			}
 			
+			tableOfContents()
 			bodyContents()
 
 			newLine()

http://git-wip-us.apache.org/repos/asf/sling-site/blob/f7d38e20/src/main/jbake/templates/logos.tpl
----------------------------------------------------------------------
diff --git a/src/main/jbake/templates/logos.tpl b/src/main/jbake/templates/logos.tpl
index 787ce40..b54fdd8 100644
--- a/src/main/jbake/templates/logos.tpl
+++ b/src/main/jbake/templates/logos.tpl
@@ -10,4 +10,4 @@ div(class:"title") {
 	  }
   }
 }
-h1(class:"draft") { yield "DRAFT 2017 WEBSITE - SLING-6955" }
\ No newline at end of file
+div(class:"draft") { yield "DRAFT 2017 WEBSITE - SLING-6955" }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/sling-site/blob/f7d38e20/src/main/jbake/templates/page.tpl
----------------------------------------------------------------------
diff --git a/src/main/jbake/templates/page.tpl b/src/main/jbake/templates/page.tpl
index 14e7356..0a93e5f 100644
--- a/src/main/jbake/templates/page.tpl
+++ b/src/main/jbake/templates/page.tpl
@@ -40,6 +40,14 @@ layout 'layout/main.tpl', true,
 				}
 			}
 		},
+		tableOfContents : contents {
+			// Temporary (?) ToC generation, until we get markdown support for that
+			// using https://github.com/nghuuphuoc/tocjs
+			div(id:"generatedToC") {}
+			yieldUnescaped "<script src='/res/jquery-3.2.1.min.js' type='text/javascript'></script>"
+			yieldUnescaped "<script src='/res/tocjs-1-1-2.js' type='text/javascript'></script>"
+			yieldUnescaped "<script type='text/javascript'>\$(document).ready(function() { \$('#generatedToC').toc({'selector':'h2,h3'});
} );</script>"
+		},
         bodyContents: contents {
             div(class:"row"){
                 div(class:"small-12 columns"){

http://git-wip-us.apache.org/repos/asf/sling-site/blob/f7d38e20/src/main/jbake/templates/toc.tpl
----------------------------------------------------------------------
diff --git a/src/main/jbake/templates/toc.tpl b/src/main/jbake/templates/toc.tpl
new file mode 100644
index 0000000..e69de29


Mime
View raw message