mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2024-06-14 11:52:32 +03:00
Require consent for GitHub repository stats if consent is enabled
This commit is contained in:
parent
f30775fa0a
commit
6b1ce14683
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -245,7 +245,7 @@
|
|||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block scripts %}
|
{% 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 %}
|
{% for path in config.extra_javascript %}
|
||||||
<script src="{{ path | url }}"></script>
|
<script src="{{ path | url }}"></script>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -4,6 +4,9 @@
|
|||||||
{% set cookies = config.extra.consent.cookies %}
|
{% set cookies = config.extra.consent.cookies %}
|
||||||
{% if config.extra.analytics and not cookies %}
|
{% if config.extra.analytics and not cookies %}
|
||||||
{% set cookies = { "analytics": "Google Analytics" } %}
|
{% set cookies = { "analytics": "Google Analytics" } %}
|
||||||
|
{% if "github.com" in config.repo_url %}
|
||||||
|
{% set _ = cookies.update({ "github": "GitHub" }) %}
|
||||||
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% set actions = config.extra.consent.actions %}
|
{% set actions = config.extra.consent.actions %}
|
||||||
{% if not actions %}
|
{% if not actions %}
|
||||||
|
@ -41,6 +41,14 @@ export interface Consent {
|
|||||||
hidden: boolean /* Consent is hidden */
|
hidden: boolean /* Consent is hidden */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Consent defaults
|
||||||
|
*/
|
||||||
|
export interface ConsentDefaults {
|
||||||
|
analytics?: boolean /* Consent for Analytics */
|
||||||
|
github?: boolean /* Consent for GitHub */
|
||||||
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
* Helper types
|
* Helper types
|
||||||
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
||||||
|
@ -35,9 +35,13 @@ import {
|
|||||||
} from "rxjs"
|
} from "rxjs"
|
||||||
|
|
||||||
import { getElement } from "~/browser"
|
import { getElement } from "~/browser"
|
||||||
|
import { ConsentDefaults } from "~/components/consent"
|
||||||
import { renderSourceFacts } from "~/templates"
|
import { renderSourceFacts } from "~/templates"
|
||||||
|
|
||||||
import { Component } from "../../_"
|
import {
|
||||||
|
Component,
|
||||||
|
getComponentElements
|
||||||
|
} from "../../_"
|
||||||
import {
|
import {
|
||||||
SourceFacts,
|
SourceFacts,
|
||||||
fetchSourceFacts
|
fetchSourceFacts
|
||||||
@ -82,13 +86,24 @@ export function watchSource(
|
|||||||
): Observable<Source> {
|
): Observable<Source> {
|
||||||
return fetch$ ||= defer(() => {
|
return fetch$ ||= defer(() => {
|
||||||
const cached = __md_get<SourceFacts>("__source", sessionStorage)
|
const cached = __md_get<SourceFacts>("__source", sessionStorage)
|
||||||
if (cached)
|
if (cached) {
|
||||||
return of(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)
|
return fetchSourceFacts(el.href)
|
||||||
.pipe(
|
.pipe(
|
||||||
tap(facts => __md_set("__source", facts, sessionStorage))
|
tap(facts => __md_set("__source", facts, sessionStorage))
|
||||||
)
|
)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.pipe(
|
.pipe(
|
||||||
catchError(() => EMPTY),
|
catchError(() => EMPTY),
|
||||||
|
@ -24,6 +24,9 @@
|
|||||||
{% set cookies = config.extra.consent.cookies %}
|
{% set cookies = config.extra.consent.cookies %}
|
||||||
{% if config.extra.analytics and not cookies %}
|
{% if config.extra.analytics and not cookies %}
|
||||||
{% set cookies = { "analytics": "Google Analytics" } %}
|
{% set cookies = { "analytics": "Google Analytics" } %}
|
||||||
|
{% if "github.com" in config.repo_url %}
|
||||||
|
{% set _ = cookies.update({ "github": "GitHub" }) %}
|
||||||
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<!-- Determine actions -->
|
<!-- Determine actions -->
|
||||||
|
Loading…
x
Reference in New Issue
Block a user