Skip to content

Commit 4323a5e

Browse files
committed
Add banner to warn about scams
1 parent c06b531 commit 4323a5e

File tree

8 files changed

+101
-1
lines changed

8 files changed

+101
-1
lines changed

Diff for: _data/messages.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
scam-banner: "**⚠️ Beware of Scams**: since Feb 2024, scammers are using [fake Scala websites to sell courses](https://www.scala-lang.org/blog/2024/03/01/fake-scala-courses.html), please check you are using an official source."

Diff for: _includes/alert-banner-inner.html

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{% comment %}use the variable 'message' to include markdown text to display in the alert.{% endcomment %}
2+
3+
<div class="new-on-the-blog alert-warning" data-message_id="{{include.message_id}}">
4+
<p>{{include.message|markdownify}}</p>
5+
<span class="hide-alert"><i class="fa fa-close"></i></span>
6+
</div>

Diff for: _includes/alert-banner.html

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{% comment %}use the variable 'message' to include markdown text to display in the alert.{% endcomment %}
2+
3+
<header id="site-header" class="header-home">
4+
{% include alert-banner-inner.html message=include.message message_id=include.message_id %}
5+
</header>

Diff for: _includes/navbar-inner.html

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<header id="site-header">
2+
{% include alert-banner.html message=site.data.messages.scam-banner message_id='scam-courses-feb-2024' %}
23
<div class="wrap">
34
<nav class="navigation" role="menu">
45
<a href="/" class="navigation-bdand">

Diff for: _layouts/frontpage.html

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<!-- Header -->
99
<header id="site-header" class="header-home">
1010
<div class="header-background">
11+
{% include alert-banner-inner.html message=site.data.messages.scam-banner message_id='scam-courses-feb-2024' %}
1112
<div class="new-on-the-blog">
1213
<p>New on the blog:
1314
{% assign newPost = site.posts.first %}

Diff for: _sass/layout/header.scss

+17
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,23 @@
1818
padding: 10px 40px;
1919
}
2020

21+
&.alert-warning {
22+
background: $warning-bg;
23+
color: $warning-text;
24+
25+
a {
26+
color: $warning-link;
27+
font-weight: bold;
28+
text-decoration: underline;
29+
30+
&:active,
31+
&:focus,
32+
&:hover {
33+
text-decoration: none;
34+
}
35+
}
36+
}
37+
2138
span {
2239
position: absolute;
2340
right: 20px;

Diff for: _sass/utils/_variables.scss

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ $apple-blue: #6dccf5;
2222
$std-link: #23aad1;
2323
$gray-heading: rgb(134, 161, 166);
2424

25+
$warning-bg: #FFA500;
26+
$warning-link: #185eb3;
27+
$warning-text: #000;
28+
2529
// $header-bg: #266270;
2630
$header-bg: #22525e;
2731
$banner-notice-bg: $gray-darkest;

Diff for: resources/js/functions.js

+66-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ $(document).ready(function() {
4343

4444
// Show Blog
4545
$(".hide").click(function() {
46-
$(".new-on-the-blog").hide();
46+
$(this).parent().hide(); // hide only the parent element of this button
4747
updatePointer();
4848
});
4949

@@ -219,6 +219,71 @@ $(document).ready(function() {
219219
}
220220
});
221221

222+
// Browser Storage Support (https://stackoverflow.com/a/41462752/2538602)
223+
function storageAvailable(type) {
224+
try {
225+
var storage = window[type],
226+
x = '__storage_test__';
227+
storage.setItem(x, x);
228+
storage.removeItem(x);
229+
return true;
230+
}
231+
catch (e) {
232+
return false;
233+
}
234+
}
235+
236+
// Store preferences in local storage and use them
237+
$(document).ready(function () {
238+
239+
const Storage = (namespace) => {
240+
return ({
241+
getPreference(key, defaultValue) {
242+
const res = localStorage.getItem(`${namespace}.${key}`);
243+
return res === null ? defaultValue : res;
244+
},
245+
setPreference(key, value, onChange) {
246+
const old = this.getPreference(key, null);
247+
if (old !== value) { // activate effect only if value changed.
248+
localStorage.setItem(`${namespace}.${key}`, value);
249+
onChange(old);
250+
}
251+
}
252+
});
253+
};
254+
255+
function setupAlertCancel(alert, storage) {
256+
const messageId = alert.data('message_id');
257+
let onHide = () => { };
258+
if (messageId) {
259+
const key = `alert.${messageId}`;
260+
const isHidden = storage.getPreference(key, 'show') === 'hidden';
261+
if (isHidden) {
262+
alert.hide();
263+
}
264+
onHide = () => storage.setPreference(key, 'hidden', _ => { });
265+
}
266+
267+
268+
alert.find('.hide-alert').click(function () {
269+
alert.hide(), onHide();
270+
});
271+
}
272+
273+
function setupAllAlertCancels(storage) {
274+
var alertBanners = $(".new-on-the-blog.alert-warning");
275+
if (alertBanners.length) {
276+
setupAlertCancel(alertBanners, storage);
277+
}
278+
}
279+
280+
if (storageAvailable('localStorage')) {
281+
const PreferenceStorage = Storage('org.scala-lang.preferences');
282+
setupAllAlertCancels(PreferenceStorage);
283+
}
284+
285+
});
286+
222287
// OS detection
223288
function getOS() {
224289
var osname = "linux";

0 commit comments

Comments
 (0)