jekyll-theme-amethyst 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/doc-search.yaml +25 -0
  3. data/.github/workflows/gem.yaml +25 -0
  4. data/.github/workflows/github-pages.yaml +47 -0
  5. data/.github/workflows/spider-check.yaml +52 -0
  6. data/.gitignore +4 -0
  7. data/404.md +9 -0
  8. data/Gemfile +6 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.md +35 -0
  11. data/_config.yml +91 -0
  12. data/_data/sidebar_api.yml +13 -0
  13. data/_data/sidebar_blog.yml +11 -0
  14. data/_data/sitenav.yml +11 -0
  15. data/_includes/opengraph.html +49 -0
  16. data/_includes/search-js.html +113 -0
  17. data/_includes/search.html +14 -0
  18. data/_includes/sidebar.html +89 -0
  19. data/_includes/version.html +28 -0
  20. data/_layouts/group.html +14 -0
  21. data/_layouts/home.html +25 -0
  22. data/_layouts/page-api.html +32 -0
  23. data/_layouts/page.html +17 -0
  24. data/_layouts/post.html +37 -0
  25. data/_layouts/posts-archive.html +17 -0
  26. data/_layouts/posts-author.html +21 -0
  27. data/_layouts/posts-tag.html +24 -0
  28. data/_layouts/posts-year.html +24 -0
  29. data/_layouts/posts.html +28 -0
  30. data/_layouts/wrapper.html +132 -0
  31. data/_posts/2006-01-26-announcing-the-blog.md +13 -0
  32. data/_posts/2006-10-18-foo-110.md +13 -0
  33. data/_posts/2007-10-18-foo-112.md +13 -0
  34. data/_posts/2008-10-18-foo-126.md +13 -0
  35. data/_posts/2009-10-18-foo-132.md +13 -0
  36. data/_posts/2010-10-18-foo-143.md +13 -0
  37. data/_posts/2011-10-18-foo-171.md +13 -0
  38. data/_posts/2012-10-18-foo-183.md +13 -0
  39. data/_posts/2013-10-18-foo-191.md +13 -0
  40. data/_posts/2014-10-18-foo-211.md +13 -0
  41. data/_posts/2015-10-18-foo-300.md +13 -0
  42. data/_posts/2017-10-18-foo-321.md +13 -0
  43. data/_posts/2018-10-18-foo-331.md +13 -0
  44. data/_posts/2019-10-18-foo-341.md +13 -0
  45. data/_posts/2020-04-01-foo-350.md +13 -0
  46. data/_posts/2020-10-18-foo-351.md +13 -0
  47. data/_posts/2021-04-01-hello-world.md +51 -0
  48. data/_sass/amethyst-variables.scss +22 -0
  49. data/_sass/amethyst.scss +906 -0
  50. data/_sass/custom.scss +2 -0
  51. data/_sass/highlight.scss +131 -0
  52. data/about.md +28 -0
  53. data/amethyst.gemspec +23 -0
  54. data/api/deprecated.md +5 -0
  55. data/api/foo/baz.md +49 -0
  56. data/api/foo/index.md +5 -0
  57. data/api/foo/quux.md +9 -0
  58. data/api/index.md +8 -0
  59. data/api/lorem/dolor.md +14 -0
  60. data/api/lorem/index.md +5 -0
  61. data/api/lorem/sit.md +15 -0
  62. data/api/removed.md +5 -0
  63. data/assets/logo-algolia.svg +1 -0
  64. data/assets/styles.scss +7 -0
  65. data/blog-archive.md +4 -0
  66. data/blog.md +4 -0
  67. data/docs/config.md +122 -0
  68. data/docs/getting-started.md +77 -0
  69. data/favicon.svg +3 -0
  70. data/guides.md +11 -0
  71. data/index.md +51 -0
  72. data/intro.md +41 -0
  73. data/lib/jekyll-theme-amethyst.rb +39 -0
  74. data/tag/event.md +5 -0
  75. data/tag/release.md +5 -0
  76. metadata +222 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ae1f567530a5c557779c453ab8ea18940c3620baa598d0362fe922bd2b6fff2f
4
+ data.tar.gz: 1c202be8204ee0d9073f337cff0b5145a3ef7019b8b1c59e835e750fe1353c72
5
+ SHA512:
6
+ metadata.gz: f633624fe399ba7a0258b0109c530d3c45155d2b6c350b3bb655895e36beb07b844275f9b479d3b37794bb98b0ac833120c79be16a9a609f5d5e8605849844f8
7
+ data.tar.gz: 0102d31b93866380a0018c5529c0c78e018ba10833eb8fa57300fe2463acfc3de746ba4d64894cfe1d4b5bf8e201bab107dbd6e1f677b57f37abb1600df8f26f
@@ -0,0 +1,25 @@
1
+ name: Update search index
2
+ on:
3
+ push:
4
+ branches:
5
+ - main
6
+
7
+ jobs:
8
+ run:
9
+ name: Update search index
10
+ runs-on: ubuntu-18.04
11
+ steps:
12
+ - uses: actions/checkout@v2
13
+
14
+ - uses: ruby/setup-ruby@v1
15
+ # If your site is in a subdirectory
16
+ # working-directory: ./
17
+ with:
18
+ ruby-version: 2.7
19
+ bundler-cache: true
20
+
21
+ - run: bundle exec jekyll algolia
22
+ # If your site is in a subdirectory
23
+ # working-directory: ./
24
+ env:
25
+ ALGOLIA_API_KEY: "${{ secrets.ALGOLIA_API_KEY }}"
@@ -0,0 +1,25 @@
1
+ name: Gem
2
+ on:
3
+ push:
4
+ tags:
5
+ - 'v*.*.*'
6
+
7
+ jobs:
8
+ gem-push:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v2
12
+ - name: Publish Gem package
13
+ env:
14
+ GEM_HOST_API_KEY: "${{ secrets.RUBYGEMS_API_PUSH }}"
15
+ # Inspired by https://github.com/bodyshopbidsdotcom/gh-action-publish-gem-on-tag/blob/1.0.1/entrypoint.sh
16
+ # Docs: https://guides.rubygems.org/command-reference/#gem-push
17
+ run: |
18
+ GIT_VERSION=$(echo "$GITHUB_REF" | cut -d'/' -f 3-)
19
+ SPEC_VERSION=$(ruby -e 'require "rubygems"; gemspec = Dir.entries(".").find { |file| file =~ /.*\.gemspec/ }; spec = Gem::Specification::load(gemspec); puts spec.version')
20
+ if [[ "$GIT_VERSION" != "v${SPEC_VERSION}" ]]; then
21
+ echo "Ignoring, git tag version differs from gem spec version."
22
+ exit 2;
23
+ fi
24
+ gem build *.gemspec
25
+ gem push *.gem
@@ -0,0 +1,47 @@
1
+ name: GitHub Pages
2
+ on:
3
+ push:
4
+ branches:
5
+ - main
6
+
7
+ jobs:
8
+ deploy:
9
+ name: Deploy
10
+ runs-on: ubuntu-20.04
11
+ env:
12
+ DEPLOY_DIR: _site/
13
+ DEPLOY_BRANCH: gh-pages
14
+ steps:
15
+ - uses: actions/checkout@v2
16
+
17
+ - name: Prepare branch
18
+ run: |
19
+ mkdir "${DEPLOY_DIR}"
20
+ cd "${DEPLOY_DIR}"
21
+ # Clone and checkout existing branch, or initialise with a new and empty branch
22
+ git clone --depth 5 --branch "${DEPLOY_BRANCH}" "https://github.com/${GITHUB_REPOSITORY}.git" . || git init -b "${DEPLOY_BRANCH}"
23
+
24
+ - uses: ruby/setup-ruby@v1
25
+ # If your site is in a subdirectory
26
+ # working-directory: ./
27
+ with:
28
+ ruby-version: 2.7
29
+ bundler-cache: true
30
+
31
+ - name: Jekyll build
32
+ # If your site is in a subdirectory
33
+ # working-directory: ./
34
+ run: bundle exec jekyll build
35
+
36
+ - name: Push to branch
37
+ # Inspired by https://github.com/helaili/jekyll-action/blob/2.2.0/entrypoint.sh
38
+ env:
39
+ GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
40
+ run: |
41
+ cd "${DEPLOY_DIR}"
42
+ touch .nojekyll
43
+ git config user.name "${GITHUB_ACTOR}" && \
44
+ git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" && \
45
+ git add . && \
46
+ git commit --allow-empty -m "Build commit ${GITHUB_SHA}" && \
47
+ git push "https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" "HEAD:${DEPLOY_BRANCH}"
@@ -0,0 +1,52 @@
1
+ name: spider-check
2
+ on:
3
+ # Once a week on Friday at 00:00
4
+ schedule:
5
+ - cron: '0 0 * * 5'
6
+ # Or manually
7
+ workflow_dispatch:
8
+ # Or when developing this workflow
9
+ push:
10
+ paths:
11
+ - .github/workflows/spider-check.yaml
12
+ pull_request:
13
+ paths:
14
+ - .github/workflows/spider-check.yaml
15
+
16
+ jobs:
17
+ spider-check:
18
+ env:
19
+ # Site address to crawl
20
+ #
21
+ # If empty, will be derived from a CNAME file or the repo name.
22
+ #
23
+ # MY_SITE: https://example.org
24
+ # MY_SITE: https://example.github.io
25
+ # MY_SITE: https://example.github.io/my-project/
26
+ #
27
+ MY_SITE:
28
+ runs-on: ubuntu-latest
29
+ steps:
30
+ - uses: actions/checkout@v2
31
+ with:
32
+ repository: jquery/hydra-link-checker
33
+ ref: v1.0.2
34
+
35
+ - name: Get site address
36
+ run: |
37
+ if [[ "$MY_SITE" == "" ]]; then
38
+ MY_SITE=$(cat CNAME 2>/dev/null || echo "")
39
+ if [[ "$MY_SITE" == "" ]]; then
40
+ REPO_BASENAME=$(echo "$GITHUB_REPOSITORY" | cut -d'/' -f 2)
41
+ REPO_OWNER=$(echo "$GITHUB_REPOSITORY" | cut -d'/' -f 1)
42
+ if [[ "$REPO_BASENAME" == "${REPO_OWNER}.github.io" ]]; then
43
+ MY_SITE="${REPO_OWNER}.github.io"
44
+ else
45
+ MY_SITE="${REPO_OWNER}.github.io/${REPO_BASENAME}"
46
+ fi
47
+ fi
48
+ echo "MY_SITE=https://${MY_SITE}" >> $GITHUB_ENV
49
+ fi
50
+
51
+ - name: Run hydra-link-checker
52
+ run: python3 hydra.py "$MY_SITE"
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ /.jekyll-cache/
2
+ /.sass-cache/
3
+ /_site/
4
+ /Gemfile.lock
data/404.md ADDED
@@ -0,0 +1,9 @@
1
+ ---
2
+ layout: page
3
+ title: Page not found
4
+ permalink: /404.html
5
+ amethyst:
6
+ hero: false
7
+ ---
8
+
9
+ <p class="lead" markdown="1">It seems we can’t find what you’re looking for.</p>
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+ ruby RUBY_VERSION
3
+
4
+ gemspec
5
+
6
+ gem "jekyll-algolia", "~> 1.7.0", group: :jekyll_plugins
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2020 Timo Tijhof
2
+ Copyright (c) 2018 Trent Willis
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ [![Build Status: spider-check](https://github.com/qunitjs/jekyll-theme-amethyst/actions/workflows/spider-check.yaml/badge.svg)](https://github.com/qunitjs/jekyll-theme-amethyst/actions/workflows/spider-check.yaml)
2
+
3
+ # Amethyst theme
4
+
5
+ This repository houses the Amethyst theme for Jekyll.
6
+
7
+ ## Getting started
8
+
9
+ To create a new site, use the **[Getting started](docs/getting-started.md)** guide,
10
+ or browse the minimal example in the [example](https://github.com/qunitjs/jekyll-theme-amethyst/tree/example) branch.
11
+
12
+ ## Credits
13
+
14
+ The theme was designed by [Trent Willis](https://github.com/trentmwillis/) in 2018 for the [qunitjs.com](https://qunitjs.com/) website ([qunitjs/qunitjs.com#151](https://github.com/qunitjs/qunitjs.com/issues/151#issuecomment-655154878)).
15
+
16
+ Thanks to [Leo Balter](https://github.com/leobalter) for initiating the use of Markdown-based static sites for QUnit in 2015 ([qunitjs/api.qunitjs.com#150](https://github.com/qunitjs/api.qunitjs.com/pull/150)).
17
+
18
+ ## Contributing
19
+
20
+ Requirements:
21
+
22
+ * [Ruby](https://www.ruby-lang.org/) (tested with Ruby 2.7+)
23
+ * [Bundler](https://bundler.io/) (if missing, install with `gem install bundler`)
24
+
25
+ To install or update Jekyll and plugins:
26
+
27
+ ```shell
28
+ bundle update
29
+ ```
30
+
31
+ To generate the site and serve it locally at <http://localhost:4000/>:
32
+
33
+ ```shell
34
+ bundle exec jekyll serve
35
+ ```
data/_config.yml ADDED
@@ -0,0 +1,91 @@
1
+ # Configuration for the Amethyst development site
2
+ #
3
+ # DO NOT COPY
4
+ #
5
+ # To create your own site with this theme, use the example branch as
6
+ # your clean and minimal starting point:
7
+ # https://github.com/qunitjs/jekyll-theme-amethyst/tree/example
8
+ #
9
+ # -------
10
+
11
+ # Site settings
12
+ #
13
+ # Docs: https://jekyllrb.com/docs/configuration/
14
+ title: Amethyst Demo
15
+ description: "An amazing website."
16
+ url: https://qunitjs.github.io
17
+ baseurl: /jekyll-theme-amethyst
18
+ # For pages (not blog posts) this is equivalant to /:title/
19
+ permalink: /:year/:month/:day/:title/
20
+ lang: en
21
+ timezone: UTC
22
+ # Files that will not be converted or published
23
+ exclude:
24
+ # Exclude internal repo files from site output
25
+ - docs
26
+ - lib
27
+ # Avoid the following on GitHub CI:
28
+ # > Error: could not read file
29
+ # > vendor/jekyll/lib/site_template/_posts/0000-00-00-welcome-to-jekyll.markdown.erb:
30
+ # > Invalid date '<%= Time.now.strftime('%Y-%m-%d %H:%M:%S %z') %>':
31
+ # > Document does not have a valid date in the YAML front matter.
32
+ - vendor
33
+ plugins:
34
+ - jekyll-theme-amethyst
35
+
36
+
37
+ # Theme settings
38
+ #
39
+ # Amethyst theme options are documented at:
40
+ # https://github.com/qunitjs/jekyll-theme-amethyst/blob/main/docs/config.md
41
+ #
42
+ theme: jekyll-theme-amethyst
43
+ amethyst:
44
+ edituri_base: https://github.com/qunitjs/jekyll-theme-amethyst/blob/main/
45
+ release_base: https://github.com/qunitjs/qunit/releases/tag/
46
+ github: qunitjs
47
+ gitter: qunitjs/qunit
48
+ # https://github.com/qunitjs/jekyll-theme-amethyst/blob/main/docs/getting-started.md#enable-algolia-search
49
+ algolia:
50
+ search_only_api_key: f37678e47d7730bbf340e904a81fbbbd
51
+
52
+
53
+ # Conversion settings
54
+ #
55
+ highlighter: rouge
56
+ markdown: kramdown
57
+ kramdown:
58
+ input: GFM
59
+ toc_levels: "1,2"
60
+
61
+
62
+ # Sass settings
63
+ #
64
+ # Docs: https://jekyllrb.com/docs/assets/#sassscss
65
+ sass:
66
+ style: compressed
67
+ sourcemap: never
68
+
69
+
70
+ # Backend search settings
71
+ #
72
+ # Docs: https://github.com/algolia/jekyll-algolia
73
+ algolia:
74
+ application_id: 4HMKKPGKKN
75
+ index_name: amethyst-demo
76
+ # By default only HTML paragraphs are indexed (and headings, albeit through a different mechanism).
77
+ # * Include list items (similar to paragraphs).
78
+ # * Include tables (index per row for better excerpts).
79
+ # * Include <pre> (typically code examples, omit if it "poisons" results too much).
80
+ nodes_to_index: "p,li,tr,pre"
81
+
82
+
83
+ # Blog archives
84
+ #
85
+ # Docs: https://github.com/jekyll/jekyll-archives/
86
+ jekyll-archives:
87
+ enabled:
88
+ - year
89
+ layout: posts-year
90
+ permalinks:
91
+ year: "/:year/"
@@ -0,0 +1,13 @@
1
+ - group: foo
2
+ expand: true
3
+
4
+ - group: lorem
5
+
6
+ - type: list
7
+ title: Other
8
+ expand: true
9
+ list:
10
+ - url: /api/deprecated/
11
+ title: Deprecated
12
+ - url: /api/removed/
13
+ title: Removed
@@ -0,0 +1,11 @@
1
+ - type: tags
2
+ title: Tags
3
+ expand: true
4
+
5
+ - type: recent
6
+ title: Recent posts
7
+ expand: true
8
+
9
+ - type: archive
10
+ title: Archives
11
+ expand: true
data/_data/sitenav.yml ADDED
@@ -0,0 +1,11 @@
1
+ - name: Guides
2
+ href: /guides/
3
+ sub:
4
+ - name: Getting Started
5
+ href: /intro/
6
+ - name: Documentation
7
+ href: /api/
8
+ - name: Blog
9
+ href: /blog/
10
+ - name: About
11
+ href: /about/
@@ -0,0 +1,49 @@
1
+ {%- assign feed_page = site.pages | where: 'url', '/feed.xml' | first -%}
2
+ {%- if feed_page -%}
3
+ <link rel="alternate" type="application/rss+xml" href="{{ feed_page.url | relative_url | escape }}" title="{{ site.title | escape }}">
4
+ {% endif -%}
5
+
6
+ {%- assign page_title = page.title -%}
7
+ {%- if page_title == nil and page.date -%}
8
+ {%- comment -%}
9
+ Deal with jekyll-archives refusing to add, or facilitate addition of, a title to archive pages.
10
+ {%- endcomment -%}
11
+ {%- if page.type == "year" -%}
12
+ {%- assign page_title = page.date | date: '%Y' -%}
13
+ {%- elsif page.type == "month" -%}
14
+ {%- assign page_title = page.date | date: '%B %Y' -%}
15
+ {%- endif -%}
16
+ {%- endif -%}
17
+
18
+ <title>{% if page.url != '/' and page_title %}{{ page_title | escape }} | {% endif %}{{ site.title | escape }}</title>
19
+
20
+ {%- comment -%}
21
+ See https://ogp.me/
22
+ {%- endcomment %}
23
+ {% capture opengraph %}
24
+
25
+ <meta property="og:title" content="{{ page_title | default: site.title | escape }}">
26
+
27
+ {% if page.excerpt %}
28
+ {%- assign excerpt = page.excerpt %}
29
+ {% elsif page.layout == "home" %}
30
+ {% assign excerpt = site.description %}
31
+ {% else %}
32
+ {% assign excerpt = "" %}
33
+ {% endif %}
34
+ {% if excerpt and excerpt != empty %}
35
+ <meta name="description" content="{{ excerpt | strip_html | truncate: 200 | normalize_whitespace | escape }}">
36
+ <meta property="og:description" content="{{ excerpt | strip_html | truncate: 200 | normalize_whitespace | escape }}">
37
+ {% endif %}
38
+
39
+ {% if site.amethyst.mastodon %}
40
+ <link rel="me" href="{{ site.amethyst.mastodon | escape }}">
41
+ {% endif %}
42
+ {% if site.amethyst.twitter %}
43
+ <meta name="twitter:creator" content="@{{ site.amethyst.twitter | escape }}">
44
+ <meta name="twitter:site" content="@{{ site.amethyst.twitter | escape }}">
45
+ {% endif %}
46
+ <meta name="twitter:card" content="summary_large_image">
47
+
48
+ {% endcapture -%}
49
+ {{ opengraph | strip_newlines }}
@@ -0,0 +1,113 @@
1
+ {%- comment -%}
2
+
3
+ For releases and integrity hashes (SRI), see:
4
+ * https://www.jsdelivr.com/package/npm/algoliasearch
5
+ * https://www.jsdelivr.com/package/npm/autocomplete.js
6
+
7
+ We use type="module" as a natural way to cut the mustard,
8
+ executing the script only on modern browsers with ES6 support,
9
+ and causing no errors on older browsers.
10
+
11
+ <https://responsivenews.tumblr.com/post/18948466399/cutting-the-mustard>
12
+ <http://web.archive.org/web/20150305005331/http://responsivenews.co.uk/post/18948466399/cutting-the-mustard>
13
+
14
+ {%- endcomment -%}
15
+ <script type="module">
16
+ const loadSearch = () => Promise.all([
17
+ new Promise((resolve) => document.body.append(Object.assign(document.createElement('script'), {
18
+ crossOrigin: 'anonymous',
19
+ integrity: 'sha256-YuyfhK9VEyfW6ejFiPbfOX2SELbFrgFU/8tU3MHuh60=',
20
+ src: 'https://cdn.jsdelivr.net/npm/algoliasearch@4.3.1/dist/algoliasearch-lite.umd.js',
21
+ onload: resolve
22
+ }))),
23
+ new Promise((resolve) => document.body.append(Object.assign(document.createElement('script'), {
24
+ crossOrigin: 'anonymous',
25
+ integrity: 'sha256-YVWQosorZnr6fALvOW9VALYuInld27RkSPkElGBdCaU=',
26
+ src: 'https://cdn.jsdelivr.net/npm/autocomplete.js@0.37.1/dist/autocomplete.min.js',
27
+ onload: resolve
28
+ })))
29
+ ]);
30
+ const input = document.querySelector('#aa-search-input');
31
+ const form = document.querySelector('#site-search-form');
32
+ let restoreFocus = false;
33
+ async function setupSearch(e) {
34
+ {% comment -%}
35
+ // Whether to restore focus after autocomplete.js replaces the input element.
36
+ // This is before the setup check to account for input before load ends.
37
+ {%- endcomment -%}
38
+ restoreFocus = restoreFocus || (e && (e.type === 'click' || e.type === 'focus'));
39
+ if (setupSearch.setup) return;
40
+ setupSearch.setup = true;
41
+ await loadSearch();
42
+
43
+ const client = algoliasearch('{{ site.amethyst.algolia.application_id | default: site.algolia.application_id }}', '{{ site.amethyst.algolia.search_only_api_key }}');
44
+ {% if site.amethyst.algolia.sources -%}
45
+ const indexSources = {{ site.amethyst.algolia.sources | jsonify }};
46
+ {%- elsif site.algolia.index_name -%}
47
+ const indexSources = [{ index: {{ site.algolia.index_name | jsonify }}, base: {{ '' | relative_url | jsonify }} }];
48
+ {%- else -%}
49
+ const indexSources = [];
50
+ {%- endif %}
51
+ const escapeString = autocomplete.escapeHighlightedString;
52
+ const autocompleteOptions = {
53
+ // Debug allows inspecting the suggestions
54
+ debug: true,
55
+ // (Re)open suggestions on (re)focus when input is non-empty
56
+ openOnFocus: true,
57
+ hint: false,
58
+ ariaLabel: 'search input',
59
+ templates: {
60
+ // https://github.com/algolia/autocomplete.js/issues/248
61
+ empty(query) {
62
+ return `No results for "${escapeString(query.query)}".`;
63
+ }
64
+ {%- if site.amethyst.algolia.branding != "none" %},
65
+ footer: '<div class="aa-footer">Search by <a class="aa-logo" href="https://algolia.com" target="_blank">Algolia</a></div>'{% endif %}
66
+ }
67
+ };
68
+ function formatURL(suggestion) {
69
+ return (suggestion.anchor && !suggestion.url.includes('#')) ? suggestion.url + '#' + suggestion.anchor : suggestion.url;
70
+ }
71
+ function newHitsSource(index, params) {
72
+ return function(query, cb) {
73
+ index.search(query, params).then(
74
+ res => { cb(res.hits, res); },
75
+ err => { cb([]); console.error(err); }
76
+ );
77
+ };
78
+ }
79
+ const autocompleteSources = indexSources.map(source => ({
80
+ source: newHitsSource(client.initIndex(source.index), { hitsPerPage: 5 }),
81
+ displayKey: '',
82
+ templates: {
83
+ suggestion(suggestion) {
84
+ const title = [ suggestion.title ].concat(suggestion.headings || []).join(' › ');
85
+ const content = suggestion._highlightResult.content && suggestion._highlightResult.content.value || '';
86
+ suggestion._href = (source.base || '') + formatURL(suggestion);
87
+ return `<a href="${suggestion._href}" tabindex="-1">
88
+ <p class="aa-suggestion_title">${title}</p>
89
+ <p class="aa-suggestion_content">${content}</p>
90
+ </a>`;
91
+ }
92
+ }
93
+ }));
94
+ const $input = autocomplete('#aa-search-input', autocompleteOptions, autocompleteSources)
95
+ .on('autocomplete:selected', (e, suggestion) => location.href = suggestion._href || suggestion.url);
96
+
97
+ if (restoreFocus) $input.focus();
98
+
99
+ // Disable fallback form
100
+ form.addEventListener('submit', (e) => {
101
+ e.preventDefault();
102
+ });
103
+ }
104
+ document.addEventListener('keydown', (e) => {
105
+ if (e.key === '/' && !(document.activeElement && /^(INPUT|TEXTAREA)$/.test(document.activeElement.tagName))) {
106
+ input.focus();
107
+ e.preventDefault();
108
+ }
109
+ });
110
+ input.addEventListener('focus', setupSearch, { once: true });
111
+ form.addEventListener('click', setupSearch, { once: true });
112
+ form.classList.add('site-search--bound');
113
+ </script>