Skip to content

Commit 9da6b00

Browse files
authored
Add banner to warn about scams (#2993)
1 parent 01450a1 commit 9da6b00

File tree

7 files changed

+89
-30
lines changed

7 files changed

+89
-30
lines changed

_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."

_includes/alert-banner.html

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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+
<div class="new-on-the-blog alert-warning" data-message_id="{{include.message_id}}">
5+
<p>{{include.message|markdownify}}</p>
6+
<span class="hide"><i class="fa fa-close"></i></span>
7+
</div>
8+
</header>

_layouts/root-content-layout.html

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
<div class="navigation-fade-screen"></div>
55

6+
{% include alert-banner.html message=site.data.messages.scam-banner message_id='scam-courses-feb-2024' %}
7+
68
{% include navbar-inner.html %}
79

810
<main id="inner-main">

_layouts/root-index-layout.html

+20-18
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,30 @@
22

33
<div class="navigation-fade-screen"></div>
44

5+
{% include alert-banner.html message=site.data.messages.scam-banner message_id='scam-courses-feb-2024' %}
6+
57
{% include navbar-inner.html %}
68

79
<main id="inner-main">
810

9-
<!-- Title -->
10-
<section class="title-page">
11-
<div class="wrap">
12-
<div class="content-title-documentation">
13-
14-
<h1>{{page.title}}</h1>
15-
<div class="search-container">
16-
<div class="icon-search">
17-
<i class="fa fa-search"></i>
18-
</div>
19-
<input type="text" class="doc-search" id="doc-search-bar" placeholder="Search in doc...">
20-
<ul class="result-container" id="result-container" style="display: none;"></ul>
21-
</div>
22-
</div>
23-
</div>
24-
</section>
25-
26-
{% comment %}Specific content from child layouts{% endcomment %} {{content}}
11+
<!-- Title -->
12+
<section class="title-page">
13+
<div class="wrap">
14+
<div class="content-title-documentation">
15+
16+
<h1>{{page.title}}</h1>
17+
<div class="search-container">
18+
<div class="icon-search">
19+
<i class="fa fa-search"></i>
20+
</div>
21+
<input type="text" class="doc-search" id="doc-search-bar" placeholder="Search in doc...">
22+
<ul class="result-container" id="result-container" style="display: none;"></ul>
23+
</div>
24+
</div>
25+
</div>
26+
</section>
27+
28+
{% comment %}Specific content from child layouts{% endcomment %} {{content}}
2729

2830
</main>
2931

_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;

_sass/utils/_variables.scss

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ $gray-light: #E5EAEA;
1818
$gray-lighter: #F0F3F3;
1919
$apple-blue: #6dccf5;
2020

21+
$warning-bg: #FFA500;
22+
$warning-link: #185eb3;
23+
$warning-text: #000;
24+
2125
//-------------------------------------------------
2226
$headings-font-color: $gray-dark;
2327
$base-font-color: #4A5659;

resources/js/functions.js

+37-12
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,6 @@ $(document).ready(function() {
7272
hljs.highlightAll();
7373
});
7474

75-
// Show Blog
76-
$(".hide").click(function() {
77-
$(".new-on-the-blog").hide();
78-
});
79-
8075
// Documentation menu dropdown toggle
8176
$(document).ready(function() { // DOM ready
8277
// If a link has a dropdown, add sub menu toggle.
@@ -435,9 +430,8 @@ $(document).ready(function() {
435430
* that when the page is refreshed, the same tab will be selected.
436431
* On page load, selects the tab corresponding to stored value.
437432
*/
438-
function setupTabs(tabs, namespace, defaultValue) {
439-
const PreferenceStorage = Storage('org.scala-lang.docs.preferences');
440-
const preferredValue = PreferenceStorage.getPreference(namespace, defaultValue);
433+
function setupTabs(tabs, namespace, defaultValue, storage) {
434+
const preferredValue = storage.getPreference(namespace, defaultValue);
441435

442436
activateTab(tabs, preferredValue)
443437

@@ -448,7 +442,7 @@ $(document).ready(function() {
448442
const parent = $(this).parent();
449443
const newValue = $(this).data('target');
450444

451-
PreferenceStorage.setPreference(namespace, newValue, oldValue => {
445+
storage.setPreference(namespace, newValue, _ => {
452446
// when we set a new scalaVersion, find scalaVersionTabs except current one
453447
// and activate those tabs.
454448
activateTab(tabs.not(parent), newValue);
@@ -459,17 +453,48 @@ $(document).ready(function() {
459453
});
460454
}
461455

462-
if (storageAvailable('localStorage')) {
456+
function setupAlertCancel(alert, storage) {
457+
const messageId = alert.data('message_id');
458+
let onHide = () => {};
459+
if (messageId) {
460+
const key = `alert.${messageId}`;
461+
const isHidden = storage.getPreference(key, 'show') === 'hidden';
462+
if (isHidden) {
463+
alert.hide();
464+
}
465+
onHide = () => storage.setPreference(key, 'hidden', _ => {});
466+
}
467+
468+
469+
alert.find('.hide').click(function() {
470+
alert.hide(), onHide();
471+
});
472+
}
473+
474+
function setupAllTabs(storage) {
463475
var scalaVersionTabs = $(".tabsection.tabs-scala-version");
464476
if (scalaVersionTabs.length) {
465-
setupTabs(scalaVersionTabs, "scalaVersion", "scala-3");
477+
setupTabs(scalaVersionTabs, "scalaVersion", "scala-3", storage);
466478
}
467479
var buildToolTabs = $(".tabsection.tabs-build-tool");
468480
if (buildToolTabs.length) {
469-
setupTabs(buildToolTabs, "buildTool", "scala-cli");
481+
setupTabs(buildToolTabs, "buildTool", "scala-cli", storage);
482+
}
483+
}
484+
485+
function setupAllAlertCancels(storage) {
486+
var alertBanners = $(".new-on-the-blog.alert-warning");
487+
if (alertBanners.length) {
488+
setupAlertCancel(alertBanners, storage);
470489
}
471490
}
472491

492+
if (storageAvailable('localStorage')) {
493+
const PreferenceStorage = Storage('org.scala-lang.docs.preferences');
494+
setupAllTabs(PreferenceStorage);
495+
setupAllAlertCancels(PreferenceStorage);
496+
}
497+
473498
});
474499

475500
// OS detection

0 commit comments

Comments
 (0)