You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@incubator.apache.org by po...@apache.org on 2017/07/06 00:21:17 UTC

[46/51] incubator git commit: Include estimated reading time.

Include estimated reading time.


Project: http://git-wip-us.apache.org/repos/asf/incubator/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator/commit/783b4342
Tree: http://git-wip-us.apache.org/repos/asf/incubator/tree/783b4342
Diff: http://git-wip-us.apache.org/repos/asf/incubator/diff/783b4342

Branch: refs/heads/master
Commit: 783b43428dce066ec6463912e354203ffbb062d5
Parents: 0d2e72f
Author: John D. Ament <jo...@apache.org>
Authored: Sat Jun 24 09:04:06 2017 -0400
Committer: John D. Ament <jo...@apache.org>
Committed: Sat Jun 24 09:04:06 2017 -0400

----------------------------------------------------------------------
 assets/js/incubator.js   |  20 ++++
 assets/js/readingTime.js | 266 ++++++++++++++++++++++++++++++++++++++++++
 templates/footer.gsp     |   4 +-
 templates/guide.gsp      |   8 +-
 4 files changed, 296 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator/blob/783b4342/assets/js/incubator.js
----------------------------------------------------------------------
diff --git a/assets/js/incubator.js b/assets/js/incubator.js
new file mode 100644
index 0000000..cab1020
--- /dev/null
+++ b/assets/js/incubator.js
@@ -0,0 +1,20 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+$('.article-body').readingTime();
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator/blob/783b4342/assets/js/readingTime.js
----------------------------------------------------------------------
diff --git a/assets/js/readingTime.js b/assets/js/readingTime.js
new file mode 100644
index 0000000..5e44b7e
--- /dev/null
+++ b/assets/js/readingTime.js
@@ -0,0 +1,266 @@
+/*!
+ Name: Reading Time
+ Dependencies: jQuery
+ Author: Michael Lynch
+ Author URL: http://michaelynch.com
+ Date Created: August 14, 2013
+ Date Updated: July 11, 2016
+ Licensed under the MIT license
+ */
+
+;(function($) {
+
+    var totalReadingTimeSeconds;
+
+    $.fn.readingTime = function(options) {
+
+        //define default parameters
+        var defaults = {
+                readingTimeTarget: '.eta',
+                readingTimeAsNumber: false,
+                wordCountTarget: null,
+                wordsPerMinute: 270,
+                round: true,
+                lang: 'en',
+                lessThanAMinuteString: '',
+                prependTimeString: '',
+                prependWordString: '',
+                remotePath: null,
+                remoteTarget: null,
+                success: function() {},
+                error: function() {}
+            },
+            plugin = this,
+            el = $(this);
+
+        //merge defaults and options
+        plugin.settings = $.extend({}, defaults, options);
+
+        //define vars
+        var s = plugin.settings;
+
+        //if no element was bound
+        if(!this.length) {
+
+            //run error callback
+            s.error.call(this);
+
+            //return so chained events can continue
+            return this;
+        }
+
+        //if s.lang is set to italian
+        if(s.lang == 'it') {
+
+            var lessThanAMinute = s.lessThanAMinuteString || "Meno di un minuto";
+
+            var minShortForm = 'min';
+
+            //if s.lang is set to french
+        } else if(s.lang == 'fr') {
+
+            var lessThanAMinute = s.lessThanAMinuteString || "Moins d'une minute";
+
+            var minShortForm = 'min';
+
+            //if s.lang is set to german
+        } else if(s.lang == 'de') {
+
+            var lessThanAMinute = s.lessThanAMinuteString || "Weniger als eine Minute";
+
+            var minShortForm = 'min';
+
+            //if s.lang is set to spanish
+        } else if(s.lang == 'es') {
+
+            var lessThanAMinute = s.lessThanAMinuteString || "Menos de un minuto";
+
+            var minShortForm = 'min';
+
+            //if s.lang is set to dutch
+        } else if(s.lang == 'nl') {
+
+            var lessThanAMinute = s.lessThanAMinuteString || "Minder dan een minuut";
+
+            var minShortForm = 'min';
+
+            //if s.lang is set to slovak
+        } else if(s.lang == 'sk') {
+
+            var lessThanAMinute = s.lessThanAMinuteString || "Menej než minútu";
+
+            var minShortForm = 'min';
+
+            //if s.lang is set to czech
+        } else if(s.lang == 'cz') {
+
+            var lessThanAMinute = s.lessThanAMinuteString || "Méně než minutu";
+
+            var minShortForm = 'min';
+
+            //if s.lang is set to Hungarian
+        } else if(s.lang == 'hu') {
+
+            var lessThanAMinute = s.lessThanAMinuteString || "Kevesebb mint egy perc";
+
+            var minShortForm = 'perc';
+
+            // if s.lang is set to Russian
+        } else if (s.lang == 'ru') {
+
+            var lessThanAMinute = s.lessThanAMinuteString || "Меньше минуты";
+
+            var minShortForm = 'мин';
+
+            //if s.lang is set to Arabic
+        } else if (s.lang == 'ar') {
+
+            var lessThanAMinute = s.lessThanAMinuteString || "أقل من دقيقة";
+
+            var minShortForm = 'دقيقة';
+
+            //if s.lang is set to Danish
+        } else if(s.lang == 'da') {
+            var lessThanAMinute = s.lessThanAMinuteString || "Mindre end et minut";
+            var minShortForm = 'min';
+
+            //if s.lang is set to Icelandic
+        } else if(s.lang == 'is') {
+            var lessThanAMinute = s.lessThanAMinuteString || "Minna en eina mínútu";
+            var minShortForm = 'min';
+
+            //if s.lang is set to Norwegian
+        } else if(s.lang == 'no') {
+            var lessThanAMinute = s.lessThanAMinuteString || "Mindre enn ett minutt";
+            var minShortForm = 'min';
+
+            //if s.lang is set to Polish
+        } else if(s.lang == 'pl') {
+            var lessThanAMinute = s.lessThanAMinuteString || "Mniej niż minutę";
+            var minShortForm = 'min';
+
+            //if s.lang is set to Russian
+        } else if(s.lang == 'ru') {
+            var lessThanAMinute = s.lessThanAMinuteString || "Меньше минуты";
+            var minShortForm = 'мой';
+
+            //if s.lang is set to Swedish
+        } else if(s.lang == 'sv') {
+            var lessThanAMinute = s.lessThanAMinuteString || "Mindre än en minut";
+            var minShortForm = 'min';
+
+            //if s.lang is set to Turkish
+        } else if(s.lang == 'tr') {
+            var lessThanAMinute = s.lessThanAMinuteString || "Bir dakikadan az";
+            var minShortForm = 'dk';
+
+            //default s.lang is english
+        } else {
+
+            var lessThanAMinute = s.lessThanAMinuteString || 'Less than a minute';
+
+            var minShortForm = 'min';
+
+        }
+
+        var setTime = function(text) {
+
+            if(text !== '') {
+
+                //split text by spaces to define total words
+                var totalWords = text.trim().split(/\s+/g).length;
+
+                //define words per second based on words per minute (s.wordsPerMinute)
+                var wordsPerSecond = s.wordsPerMinute / 60;
+
+                //define total reading time in seconds
+                totalReadingTimeSeconds = totalWords / wordsPerSecond;
+
+                //define reading time in minutes
+                //if s.round is set to true
+                if(s.round === true) {
+
+                    var readingTimeMinutes = Math.round(totalReadingTimeSeconds / 60);
+
+                    //if s.round is set to false
+                } else {
+
+                    var readingTimeMinutes = Math.floor(totalReadingTimeSeconds / 60);
+
+                }
+
+                //define remaining reading time seconds
+                var readingTimeSeconds = Math.round(totalReadingTimeSeconds - readingTimeMinutes * 60);
+
+                //if s.round is set to true
+                if(s.round === true) {
+
+                    //if minutes are greater than 0
+                    if(readingTimeMinutes > 0) {
+
+                        //set reading time by the minute
+                        $(s.readingTimeTarget).text(s.prependTimeString + readingTimeMinutes + ((!s.readingTimeAsNumber) ? ' ' + minShortForm : ''));
+
+                    } else {
+
+                        //set reading time as less than a minute
+                        $(s.readingTimeTarget).text((!s.readingTimeAsNumber) ? s.prependTimeString + lessThanAMinute : readingTimeMinutes);
+
+                    }
+
+                    //if s.round is set to false
+                } else {
+
+                    //format reading time
+                    var readingTime = readingTimeMinutes + ':' + readingTimeSeconds;
+
+                    //set reading time in minutes and seconds
+                    $(s.readingTimeTarget).text(s.prependTimeString + readingTime);
+
+                }
+
+                //if word count container isn't blank or undefined
+                if(s.wordCountTarget !== '' && s.wordCountTarget !== undefined) {
+
+                    //set word count
+                    $(s.wordCountTarget).text(s.prependWordString + totalWords);
+
+                }
+
+                //run success callback
+                s.success.call(this);
+
+            } else {
+
+                //run error callback
+                s.error.call(this, 'The element is empty.');
+            }
+
+        };
+
+        //for each element
+        el.each(function() {
+
+            //if s.remotePath and s.remoteTarget aren't null
+            if(s.remotePath != null && s.remoteTarget != null) {
+
+                //get contents of remote file
+                $.get(s.remotePath, function(data) {
+
+                    //set time using the remote target found in the remote file
+                    setTime($('<div>').html(data).find(s.remoteTarget).text());
+
+                });
+
+            } else {
+
+                //set time using the targeted element
+                setTime(el.text());
+            }
+        });
+
+        return totalReadingTimeSeconds;
+    }
+
+
+})(jQuery);
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator/blob/783b4342/templates/footer.gsp
----------------------------------------------------------------------
diff --git a/templates/footer.gsp b/templates/footer.gsp
index 05972f8..1e292a2 100644
--- a/templates/footer.gsp
+++ b/templates/footer.gsp
@@ -12,6 +12,8 @@
     <script src="<%if (content.rootpath) {%>${content.rootpath}<% } else { %><% }%>js/jquery-1.11.1.min.js"></script>
     <script src="<%if (content.rootpath) {%>${content.rootpath}<% } else { %><% }%>js/bootstrap.min.js"></script>
     <script src="<%if (content.rootpath) {%>${content.rootpath}<% } else { %><% }%>js/prettify.js"></script>
-    
+    <script src="<%if (content.rootpath) {%>${content.rootpath}<% } else { %><% }%>js/readingTime.js"></script>
+    <script src="<%if (content.rootpath) {%>${content.rootpath}<% } else { %><% }%>js/incubator.js"></script>
+
   </body>
 </html>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator/blob/783b4342/templates/guide.gsp
----------------------------------------------------------------------
diff --git a/templates/guide.gsp b/templates/guide.gsp
index 2d677bd..e0182b9 100644
--- a/templates/guide.gsp
+++ b/templates/guide.gsp
@@ -6,6 +6,12 @@
     <h1>Guide :: ${content.title}</h1>
 </div>
 
+<div class="article-body">
+
+Estimated Reading Time: <span class="eta"></span>
+
 <p>${content.body}</p>
 
-<%include "footer.gsp"%>
\ No newline at end of file
+</div>
+
+<%include "footer.gsp"%>


---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@incubator.apache.org
For additional commands, e-mail: cvs-help@incubator.apache.org