Require consent for GitHub repository stats if consent is enabled

This commit is contained in:
squidfunk 2022-09-18 15:26:59 +02:00
parent f30775fa0a
commit 6b1ce14683
7 changed files with 41 additions and 12 deletions

View File

@ -245,7 +245,7 @@
</script>
{% endblock %}
{% block scripts %}
<script src="{{ 'assets/javascripts/bundle.d691e9de.min.js' | url }}"></script>
<script src="{{ 'assets/javascripts/bundle.6cef57a0.min.js' | url }}"></script>
{% for path in config.extra_javascript %}
<script src="{{ path | url }}"></script>
{% endfor %}

View File

@ -4,6 +4,9 @@
{% set cookies = config.extra.consent.cookies %}
{% if config.extra.analytics and not cookies %}
{% set cookies = { "analytics": "Google Analytics" } %}
{% if "github.com" in config.repo_url %}
{% set _ = cookies.update({ "github": "GitHub" }) %}
{% endif %}
{% endif %}
{% set actions = config.extra.consent.actions %}
{% if not actions %}

View File

@ -41,6 +41,14 @@ export interface Consent {
hidden: boolean /* Consent is hidden */
}
/**
* Consent defaults
*/
export interface ConsentDefaults {
analytics?: boolean /* Consent for Analytics */
github?: boolean /* Consent for GitHub */
}
/* ----------------------------------------------------------------------------
* Helper types
* ------------------------------------------------------------------------- */

View File

@ -35,9 +35,13 @@ import {
} from "rxjs"
import { getElement } from "~/browser"
import { ConsentDefaults } from "~/components/consent"
import { renderSourceFacts } from "~/templates"
import { Component } from "../../_"
import {
Component,
getComponentElements
} from "../../_"
import {
SourceFacts,
fetchSourceFacts
@ -82,13 +86,24 @@ export function watchSource(
): Observable<Source> {
return fetch$ ||= defer(() => {
const cached = __md_get<SourceFacts>("__source", sessionStorage)
if (cached)
if (cached) {
return of(cached)
else
} else {
/* Check if consent is configured and was given */
const els = getComponentElements("consent")
if (els.length) {
const consent = __md_get<ConsentDefaults>("__consent")
if (!(consent && consent.github))
return EMPTY
}
/* Fetch repository facts */
return fetchSourceFacts(el.href)
.pipe(
tap(facts => __md_set("__source", facts, sessionStorage))
)
}
})
.pipe(
catchError(() => EMPTY),

View File

@ -24,6 +24,9 @@
{% set cookies = config.extra.consent.cookies %}
{% if config.extra.analytics and not cookies %}
{% set cookies = { "analytics": "Google Analytics" } %}
{% if "github.com" in config.repo_url %}
{% set _ = cookies.update({ "github": "GitHub" }) %}
{% endif %}
{% endif %}
<!-- Determine actions -->