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>
|
||||
{% 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 %}
|
||||
|
@ -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 %}
|
||||
|
@ -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
|
||||
* ------------------------------------------------------------------------- */
|
||||
|
@ -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),
|
||||
|
@ -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 -->
|
||||
|
Loading…
Reference in New Issue
Block a user