Skip to content
Snippets Groups Projects
Commit bd1d9000 authored by Olivier Goulet's avatar Olivier Goulet
Browse files

feat: drop youtube data api

parent de4f290b
No related branches found
No related tags found
No related merge requests found
...@@ -34,7 +34,6 @@ pluralizeListTitles = false ...@@ -34,7 +34,6 @@ pluralizeListTitles = false
call_for_action_text = "SPONSOR" call_for_action_text = "SPONSOR"
call_for_action_url = "https://www.eclipse.org/donate/ecdtools/" call_for_action_url = "https://www.eclipse.org/donate/ecdtools/"
call_for_action_icon = "fa-star" call_for_action_icon = "fa-star"
youtube_api_token = "AIzaSyD39bhVP9YusHLR4Q_gcMwuSuYEMXLja9A"
[taxonomies] [taxonomies]
category = "categories" category = "categories"
......
...@@ -17,7 +17,6 @@ import 'eclipsefdn-solstice-assets/js/solstice/eclipsefdn.projects' ...@@ -17,7 +17,6 @@ import 'eclipsefdn-solstice-assets/js/solstice/eclipsefdn.projects'
import './src/eclipseApi' import './src/eclipseApi'
import './src/projects-home.js' import './src/projects-home.js'
import './adopters-alternate.js' import './adopters-alternate.js'
import addLatestVideoToWhatsNew from './src/playlists'
const solsticeSliderHome = () => { const solsticeSliderHome = () => {
var owl = $('.solstice-slider-home'); var owl = $('.solstice-slider-home');
...@@ -33,7 +32,6 @@ const solsticeSliderHome = () => { ...@@ -33,7 +32,6 @@ const solsticeSliderHome = () => {
$(window).on("load", function() { $(window).on("load", function() {
solsticeSliderHome(); solsticeSliderHome();
addLatestVideoToWhatsNew();
}); });
$("body").on("shown.ef.featured_story", function(e) { $("body").on("shown.ef.featured_story", function(e) {
......
/*!
* Copyright (c) 2022 Eclipse Foundation, Inc.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* Contributors:
* Olivier Goulet <olivier.goulet@eclipse-foundation.org>
*
* SPDX-License-Identifier: EPL-2.0
*/
const apiBaseUrl = 'https://youtube.googleapis.com/youtube/v3'
const getPlaylistFromAPI = async (token, playlistId) => {
try {
const response = await fetch(`${apiBaseUrl}/playlistItems?key=${token}&playlistId=${playlistId}&part=snippet`);
const responseJson = await response.json();
return { playlist: responseJson }
} catch (error) {
return { error }
}
}
const getPlaylists = async (token, playlistIds) => {
// Retrieve playlists from API
let playlists = await Promise.all(playlistIds
.map(async (id) => {
const { playlist, error } = await getPlaylistFromAPI(token, id);
if (error) return;
return playlist;
}))
return playlists.filter(p => typeof p !== 'undefined');
}
const getLatestVideoFromPlaylist = (playlists) => {
let latestVideos = playlists
.map(playlist => playlist.items)
.flat()
.sort((v1, v2) => v1.snippet.publishedAt < v2.snippet.publishedAt ? 1 : -1);
const latestVideo = latestVideos[0];
return {
date: new Date(latestVideo.snippet.publishedAt),
title: latestVideo.snippet.title,
description: latestVideo.snippet.description,
videoId: latestVideo.snippet.resourceId.videoId
};
}
const addLatestVideoToWhatsNew = async () => {
const elem = document.querySelector('.whats-new-playlist');
if (!elem) return;
const token = elem['youtubeAPIToken'];
if (!token) return;
// Load static playlist data from data attribute
const playlistBuffer = Buffer.from(elem.dataset.playlists, 'base64');
const staticPlaylistsData = JSON.parse(playlistBuffer.toString());
const playlistIds = staticPlaylistsData.map(p => p.playlist_id);
// Obtain the latest video from all playlists
const playlists = await getPlaylists(token, playlistIds);
const latestVideo = getLatestVideoFromPlaylist(playlists);
const titleElem = document.querySelector('.whats-new-title');
titleElem.innerHTML = latestVideo.title;
titleElem.href = `https://www.youtube.com/watch?v=${latestVideo.videoId}`
const descriptionElem = document.querySelector('.whats-new-description');
descriptionElem.innerHTML = latestVideo.description.substring(0, 200) + '...';
const dateOptions = {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
hourCycle: 'h24',
};
const dateElem = document.querySelector('.whats-new-date');
let formattedDate = latestVideo.date
.toLocaleDateString(undefined, dateOptions)
.toString()
.replace('at', '-')
dateElem.innerHTML = formattedDate;
}
export default addLatestVideoToWhatsNew;
\ No newline at end of file
...@@ -24,11 +24,16 @@ ...@@ -24,11 +24,16 @@
<div id="news-list-container" class="news-items" data-pagination="false" data-news-count="1" data-publish-target="ecd_tools"></div> <div id="news-list-container" class="news-items" data-pagination="false" data-news-count="1" data-publish-target="ecd_tools"></div>
<p class="whats-new-view-all"><a href="/resources/news">View All News <i class="fa fa-angle-right" aria-hidden="true"></i></a></p> <p class="whats-new-view-all"><a href="/resources/news">View All News <i class="fa fa-angle-right" aria-hidden="true"></i></a></p>
</div> </div>
<div class="col-sm-10 match-height-item-by-row whats-new-item whats-new-playlist" data-playlists="{{ .Site.Data.playlists | jsonify | base64Encode }}"> <div class="col-sm-10 match-height-item-by-row whats-new-item whats-new-playlist">
<div class="whats-new-icon"><img alt="Videos icon" src="images/ecdtools/home/videos.svg"></div> <div class="whats-new-icon"><img alt="" src="images/ecdtools/home/videos.svg"></div>
<p class="whats-new-date">...</p> <p class="whats-new-date">Wednesday, July 31, 2024 - 10:38</p>
<h4><a class="whats-new-title" href="#whats-new">...</a></h4> <h4><a class="whats-new-title" href="https://www.youtube.com/watch?v=KVNTKfomnR0">Cloud Tool Time - Enhance Developer Experience with VSCode Extensions and AI</a></h4>
<p class="whats-new-description">...</p> <p class="whats-new-description">
Over the past year, we've seen a huge shift in software
development thanks to Large Language Models (LLMs). We're
all trying to figure out how to integrate these
technologies into our IDEs to boost pr...
</p>
<p class="whats-new-view-all"><a href="/resources/videos">View All Videos <i class="fa fa-angle-right" aria-hidden="true"></i></a></p> <p class="whats-new-view-all"><a href="/resources/videos">View All Videos <i class="fa fa-angle-right" aria-hidden="true"></i></a></p>
</div> </div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment