Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #481 Google Calendar #549

Merged
merged 1 commit into from
Dec 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 19 additions & 22 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ save_scroll: false
excerpt_description: true

# Automatically Excerpt. Not recommend.
# Please use <!-- more --> in the post to control excerpt accurately.
# Use <!-- more --> in the post to control excerpt accurately.
auto_excerpt:
enable: false
length: 150
Expand Down Expand Up @@ -527,9 +527,9 @@ changyan:
appid:
appkey:

# Valine.
# Valine
# You can get your appid and appkey from https://leancloud.cn
# more info please open https://valine.js.org
# More info available at https://valine.js.org
valine:
enable: false # When enable is set to be true, leancloud_visitors is recommended to be closed for the re-initialization problem within different leancloud adk version.
appid: # your leancloud application appid
Expand Down Expand Up @@ -634,7 +634,7 @@ needmoreshare2:
#cnzz_siteid:

# Application Insights
# See https://azure.microsoft.com/en-us/services/application-insights
# See: https://azure.microsoft.com/en-us/services/application-insights
#application_insights:

# Post widgets & FB/VK comments settings.
Expand All @@ -657,7 +657,7 @@ facebook_comments_plugin:
width: 100% # default width is 550px
scheme: light # default scheme is light (light or dark)

# VKontakte API Support.
# VKontakte API Support
# To get your AppID visit https://vk.com/editapp?act=create
vkontakte_api:
enable: false
Expand All @@ -681,14 +681,14 @@ leancloud_visitors:
app_id: #<app_id>
app_key: #<app_key>
# Dependencies: https://github.com/theme-next/hexo-leancloud-counter-security
# If you don't care about security in lc counter and just want to use it directly
# (without hexo-leancloud-counter-security plugin), set the `security` to `false`.
# If you don't care about security in leancloud counter and just want to use it directly
# (without hexo-leancloud-counter-security plugin), set `security` to `false`.
security: true
betterPerformance: false

# Another tool to show number of visitors to each article.
# visit https://console.firebase.google.com/u/0/ to get apiKey and projectId
# visit https://firebase.google.com/docs/firestore/ to get more information about firestore
# Visit https://console.firebase.google.com/u/0/ to get apiKey and projectId.
# Visit https://firebase.google.com/docs/firestore/ to get more information about firestore.
firestore:
enable: false
collection: articles #required, a string collection name to access firestore database
Expand All @@ -713,25 +713,22 @@ busuanzi_count:
# Tencent MTA ID
#tencent_mta:

# Enable baidu push so that the blog will push the url to baidu automatically which is very helpful for SEO
# Enable baidu push so that the blog will push the url to baidu automatically which is very helpful for SEO.
baidu_push: false

# Google Calendar
# Share your recent schedule to others via calendar page
#
# API Documentation:
# https://developers.google.com/google-apps/calendar/v3/reference/events/list
# Share your recent schedule to others via calendar page.
# API Documentation: https://developers.google.com/google-apps/calendar/v3/reference/events/list
# Enabled APIs and services
# api_key: https://console.developers.google.com
# Create & manage a public Google calendar: https://support.google.com/calendar/answer/37083?hl=en
# Create & manage a public Google calendar: https://support.google.com/calendar/answer/37083
calendar:
enable: false
calendar_id: <required> # Your Google account E-Mail
api_key: <required>
orderBy: startTime
offsetMax: 24 # Time Range
offsetMin: 4 # Time Range
timeZone:
showDeleted: false
singleEvents: true
maxResults: 250
Expand Down Expand Up @@ -775,7 +772,7 @@ bookmark:
# Tags Settings
# ---------------------------------------------------------------

# Note tag (bs-callout).
# Note tag (bs-callout)
note:
# Note tag style values:
# - simple bs-callout old alert style. Default.
Expand All @@ -789,10 +786,10 @@ note:
# Offset also applied to label tag variables. This option can work with disabled note tag.
light_bg_offset: 0

# Label tag.
# Label tag
label: true

# Tabs tag.
# Tabs tag
tabs:
enable: true
transition:
Expand Down Expand Up @@ -833,9 +830,9 @@ motion:
sidebar: slideUpIn

# Fancybox. There is support for old version 2 and new version 3.
# Please, choose only any one variant, do not need to install both.
# For install 2.x: https://github.com/theme-next/theme-next-fancybox
# For install 3.x: https://github.com/theme-next/theme-next-fancybox3
# Choose only any one variant, do not need to install both.
# To install 2.x: https://github.com/theme-next/theme-next-fancybox
# To install 3.x: https://github.com/theme-next/theme-next-fancybox3
fancybox: false

# Added switch option for separated repo in 6.0.0.
Expand Down
1 change: 0 additions & 1 deletion layout/_third-party/needsharebutton.swig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
{% set needmoreshare2_js = theme.vendors.needmoreshare2_js %}
{% endif %}
<script src="{{ needmoreshare2_js }}"></script>

<script>
{% if theme.needmoreshare2.postbottom.enable %}
pbOptions = {};
Expand Down
2 changes: 1 addition & 1 deletion layout/_third-party/pdf.swig
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
if (!href) return;
if (href.endsWith(".pdf") || href.endsWith(".pdf/")) {
var id = "pdf" + Math.floor(Math.random() * 10000);
$(this).after("<div id='" + id + "'></div>").remove();
$(this).after(`<div id="${id}"></div>`).remove();
PDFObject.embed(href, "#" + id, options);
}
});
Expand Down
116 changes: 54 additions & 62 deletions layout/_third-party/schedule.swig
Original file line number Diff line number Diff line change
@@ -1,58 +1,51 @@
{% if theme.calendar.enable %}
{% if page.type == 'schedule' %}
{% if theme.calendar.enable && page.type === 'schedule' %}

<script>

// Initialization
var _n = function(arg) { if(arg) return arg; else return void 0;}

var cal_data = void 0;
function _n(arg) {
if (arg) return arg;
else return void 0;
}

var now = new Date();
var timeMax = new Date();
var timeMin = new Date();

// Read config form theme config file
var calId = _n('{{ theme.calendar.calendar_id }}') ;
var apiKey = _n('{{ theme.calendar.api_key }}') ;
var orderBy = _n('{{ theme.calendar.ordarBy }}') || 'startTime';
var showLocation = _n('{{ theme.calendar.showLocation }}') || 'false' ;
var offsetMax = _n( {{ theme.calendar.offsetMax }} ) || 72 ;
var offsetMin = _n( {{ theme.calendar.offsetMin }} ) || 4 ;
var timeZone = _n( {{ theme.calendar.timeZone }} ) || void 0 ;
var showDeleted = _n( {{ theme.calendar.showDeleted }} ) || 'false' ;
var singleEvents = _n( {{ theme.calendar.singleEvents }} ) || 'true' ;
var maxResults = _n( {{ theme.calendar.maxResults }} ) || '250' ;
var calId = _n('{{ theme.calendar.calendar_id }}') ;
var apiKey = _n('{{ theme.calendar.api_key }}') ;
var orderBy = _n('{{ theme.calendar.ordarBy }}') || 'startTime';
var showLocation = _n('{{ theme.calendar.showLocation }}') || 'false' ;
var offsetMax = _n( {{ theme.calendar.offsetMax }} ) || 72 ;
var offsetMin = _n( {{ theme.calendar.offsetMin }} ) || 4 ;
var showDeleted = _n( {{ theme.calendar.showDeleted }} ) || 'false' ;
var singleEvents = _n( {{ theme.calendar.singleEvents }} ) || 'true' ;
var maxResults = _n( {{ theme.calendar.maxResults }} ) || '250' ;

timeMax.setHours(now.getHours() + offsetMax);
timeMin.setHours(now.getHours() - offsetMin);

// Build URL
BASE_URL = 'https://www.googleapis.com/calendar/v3/calendars/';
FIELD_KEY = 'key';
FIELD_ORDERBY = 'orderBy';
FIELD_TIMEMAX = 'timeMax';
FIELD_TIMEMIN = 'timeMin';
FIELD_TIMEZONE = 'timeZone';
FIELD_SHOWDELETED = 'showDeleted';
FIELD_SINGLEEVENTS = 'singleEvents';
FIELD_MAXRESULTS = 'maxResults';

timeMaxISO = timeMax.toISOString();
timeMinISO = timeMin.toISOString();

request_url = BASE_URL + calId + '/events?' +
FIELD_KEY + '=' + apiKey + '&' +
FIELD_ORDERBY + '=' + orderBy + '&' +
FIELD_TIMEMAX + '=' + timeMaxISO + '&' +
FIELD_TIMEMIN + '=' + timeMinISO + '&' +
FIELD_SHOWDELETED + '=' + showDeleted + '&' +
FIELD_SINGLEEVENTS + '=' + singleEvents + '&' +
FIELD_MAXRESULTS + '=' + maxResults;

if (timeZone) {
request_url = request_url + '&' + FIELD_TIMEZONE + '=' + timeZone;
}
BASE_URL = 'https://www.googleapis.com/calendar/v3/calendars/';
FIELD_KEY = 'key';
FIELD_ORDERBY = 'orderBy';
FIELD_TIMEMAX = 'timeMax';
FIELD_TIMEMIN = 'timeMin';
FIELD_SHOWDELETED = 'showDeleted';
FIELD_SINGLEEVENTS = 'singleEvents';
FIELD_MAXRESULTS = 'maxResults';

timeMaxISO = timeMax.toISOString();
timeMinISO = timeMin.toISOString();

request_url = BASE_URL + calId + '/events?' +
FIELD_KEY + '=' + apiKey + '&' +
FIELD_ORDERBY + '=' + orderBy + '&' +
FIELD_TIMEMAX + '=' + timeMaxISO + '&' +
FIELD_TIMEMIN + '=' + timeMinISO + '&' +
FIELD_SHOWDELETED + '=' + showDeleted + '&' +
FIELD_SINGLEEVENTS + '=' + singleEvents + '&' +
FIELD_MAXRESULTS + '=' + maxResults;

fetchData();
var queryLoop = setInterval(fetchData, 60000);
Expand All @@ -67,17 +60,18 @@ function fetchData() {

// clean the event list
$eventList.html("");
var prevEnd = 0; // used to decide where to insert an <hr>
var prevEnd = 0; // used to decide where to insert an <hr/>

data['items'].forEach((event) => {
data.items.forEach((event) => {

// parse data
var start = new Date(event.start.dateTime);
var end = new Date(event.end.dateTime);
var utc = new Date().getTimezoneOffset() * 60000;
var start = event.start.dateTime = new Date(event.start.dateTime || (new Date(event.start.date).getTime() + utc));
var end = event.end.dateTime = new Date(event.end.dateTime || (new Date(event.end.date).getTime() + utc));

tense = judgeTense(now, start, end); // 0:now 1:future -1:past

if (tense == 1 && prevEnd < now) $eventList.append('<hr>');
if (tense == 1 && prevEnd < now) $eventList.append('<hr/>');

eventDOM = buildEventDOM(tense, event);
$eventList.append(eventDOM);
Expand Down Expand Up @@ -118,15 +112,15 @@ function getRelativeTime(current, previous) {
}

function judgeTense(now, eventStart, eventEnd) {
if (eventEnd < now) { return -1; }
else if (eventStart > now) { return 1; }
else { return 0; }
if (eventEnd < now) { return -1; }
else if (eventStart > now) { return 1; }
else { return 0; }
}

function buildEventDOM(tense, event) {
var tenseClass = "";
var start = new Date(event.start.dateTime);
var end = new Date(event.end.dateTime);
var start = event.start.dateTime;
var end = event.end.dateTime;
switch(tense) {
case 0 : // now
tenseClass = "event-now";
Expand All @@ -142,22 +136,22 @@ function buildEventDOM(tense, event) {
}
durationFormat = {
weekday: 'short',
hour: '2-digit',
minute:'2-digit'
hour : '2-digit',
minute : '2-digit'
};
relativeTimeStr = (tense == 0) ? "NOW" : getRelativeTime(now, start);
durationStr = start.toLocaleTimeString([], durationFormat) + " - " +
end.toLocaleTimeString([], durationFormat);

liOpen = `<li class="event ${tenseClass}">`;
liClose = `</li>`;
h2Open = `<h2 class="event-summary">`;
h2Close = `</h2>`;
liOpen = `<li class="event ${tenseClass}">`;
liClose = `</li>`;
h2Open = `<h2 class="event-summary">`;
h2Close = `</h2>`;

locationDOM = "";
if (showLocation && event['location']) {
if (showLocation && event.location) {
locationDOM = `<span class="event-location event-details">
${event['location']}
${event.location}
</span>`;
}
relativeTimeDOM = `<span class="event-relative-time">
Expand All @@ -170,16 +164,14 @@ function buildEventDOM(tense, event) {
eventContent =
liOpen +
h2Open +
event['summary'] +
event.summary +
relativeTimeDOM+
h2Close +
locationDOM +
durationDOM +
liClose;
return eventContent;
}

</script>

{% endif %}
{% endif %}
1 change: 0 additions & 1 deletion source/css/_common/scaffolding/base.styl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

::selection {
background: $selection-bg;
color: $selection-color;
Expand Down