diff --git a/docs/lib/site.dart b/docs/lib/site.dart new file mode 100644 index 00000000..1e45985d --- /dev/null +++ b/docs/lib/site.dart @@ -0,0 +1,43 @@ +import 'dart:html'; + +// ignore: non_constant_identifier_names +void built_site_main() { + if (window.location.pathname?.startsWith('/search') == true) { + final privacyTag = document.getElementById('privacy'); + void loadSearchResults() { + privacyTag?.remove(); + + final element = ScriptElement() + ..async = true + // ignore: unsafe_html + ..src = + 'https://cse.google.com/cse.js?cx=002567324444333206795:_yptu7lact8'; + document.head?.append(element); + } + + final storage = window.localStorage; + + // Only load search results after consent. + if (storage.containsKey('google_ok')) { + loadSearchResults(); + } else { + privacyTag?.style.visibility = 'visible'; + document.getElementById('accept')?.onClick.first.whenComplete(() { + storage['google_ok'] = ''; + loadSearchResults(); + }); + } + } + + // Make the search box functional + for (final element in document + .querySelectorAll('.td-search-input') + .whereType()) { + element.onKeyPress.where((e) => e.keyCode == 13).first.whenComplete(() { + final value = element.value; + if (value != null && value.isNotEmpty) { + window.location.assign('/search/?q=${Uri.encodeQueryComponent(value)}'); + } + }); + } +} diff --git a/docs/pages/search.html b/docs/pages/search.html new file mode 100644 index 00000000..a10f0b11 --- /dev/null +++ b/docs/pages/search.html @@ -0,0 +1,6 @@ +--- +data: + title: Search results +path: /search +template: search.html +--- diff --git a/docs/templates/partials/hooks/head-end.html b/docs/templates/partials/hooks/head-end.html index 2dcf509e..de361564 100644 --- a/docs/templates/partials/hooks/head-end.html +++ b/docs/templates/partials/hooks/head-end.html @@ -1,2 +1,3 @@ - - +{% if page.path == '/search' %} + +{% endif %} diff --git a/docs/templates/search.html b/docs/templates/search.html new file mode 100644 index 00000000..f6e2d9b6 --- /dev/null +++ b/docs/templates/search.html @@ -0,0 +1,22 @@ +{% capture main %} +
+
+

Search results

+ +
+

+ The search results on this site are powered by Google. + By clicking continue and continuing to use the search function on this site, + you agree to the transmission of data to Google under + Google's privacy policy. +

+ + Continue and show results + +
+ +
+
+
+{% endcapture %} +{% include "_default/baseof.html" %} diff --git a/docs/theme.yaml b/docs/theme.yaml index 7f946f1f..2d16e90d 100644 --- a/docs/theme.yaml +++ b/docs/theme.yaml @@ -1,2 +1,3 @@ contributes: sass: 'lib/_style.scss' + dart: 'lib/site.dart' diff --git a/docs/web/search.scss b/docs/web/search.scss new file mode 100644 index 00000000..55bc3fb6 --- /dev/null +++ b/docs/web/search.scss @@ -0,0 +1,3 @@ +#privacy { + visibility: hidden; +} diff --git a/docs/website.yaml b/docs/website.yaml index 6502bc58..4e4212a5 100644 --- a/docs/website.yaml +++ b/docs/website.yaml @@ -8,7 +8,7 @@ site: github_repo: "https://github.com/simolus3/moor" github_subdir: "docs/" github_branch: master - # gcs_engine_id: "002567324444333206795:_yptu7lact8" + gcs_engine_id: set # this just needs to be set so that the search box shows sidebar_search_disable: true links: