Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search functions on localhost, but not on a remote server #323

Closed
metacodez opened this issue Jan 14, 2019 · 5 comments
Closed

Search functions on localhost, but not on a remote server #323

metacodez opened this issue Jan 14, 2019 · 5 comments

Comments

@metacodez
Copy link

First of all I love this Theme! I upgraded lately from an old version of the Theme to the newest one basically by setting up everything as described. All looks very fine locally.

When I start JEKYLL_ENV=production bundle exec jekyll build and upload the site to my server on http://www.refcodes.org, the search fails: No search results are schown. The Firefox Console states:

Loading failed for the <script> with source “http://www.refcodes.org/assets/js/search-data.json”.

When I run the site locally via bundle exec jekyll serve the search functions all fine.

I tested in Arch Linux using the following brosers and on some Android phones:
Firefox 64.0.2, Chromium Version 71.0.3578.98.

Seems the the Browser has problems loading search-data.json, though when targeting the URL http://www.refcodes.org/assets/js/search-data.json its all there.

I am not sure whether this is a theme issue or located in one of the external dependencies, mayby some one else had a similar issue.

Any help is appreciated, thanks beforehand and best regards,
Siegfried

@mmistakes
Copy link
Owner

Not a theme issue. Your search-data.json has an issue which it can't be parsed, that's why search isn't working.

If you browse to http://www.refcodes.org/assets/js/search-data.json
You'll see the following errors:

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
Content Security Policy: The page’s settings blocked the loading of a resource at http://www.refcodes.org/favicon.ico (“default-src”).

CORS errors are almost always related to your hosting server. This is why it's working for you locally and not on your production server. I've only ever used Apache servers and you can fix these sorts of things with a .htaccess file. You'll probably have to search around for the actual fix, but I'm fairly confident the theme is working as intended.

@metacodez
Copy link
Author

Seems to be a problem with a JavaScript being loaded by the site with the file-suffix json and not js. This addresses the file search-data.json included as script in the lunr-search-scripts.html file (inside the _includes folder).

I modified the lunr-search-scripts.html to load search-data.js instead of search-data.json and made loading all of the scripts relative to the site and not absolute: This way the scripts are always loaded from the hosting server, even if the site is reverse-proxied. After site-generation, I post-proces the _site folder to rename search-data.json to search-data.js. Yes, this renaming-part is hackish :-( Now the search data loads fine.

The reason is that my browser refuses to load a file with a suffix json using a <script> tag which actually is no JSON but moreover a JavaScript file:

The search-data.json is actually JavaScript, having an assignment operator inside, and therefore it is no static data structure such as JSON any more. The browser thinks this is a security issue and blocks the "JSON" from being executed,

Original lunr-search-scripts.html before my modifications:

  <script src="{{ '/assets/js/lunr/lunr.min.js' | absolute_url }}"></script>
  <script src="{{ '/assets/js/search-data.json' | absolute_url }}"></script>
  {%- unless lang == "en" -%}
    <script src="{{ '/assets/js/lunr/lunr.stemmer.support.min.js' | absolute_url }}"></script>
    <script src="{{ '/assets/js/lunr/lunr.' | append: lang | append: '.min.js' | absolute_url }}"></script>
  {%- endunless %}

I changed it as follows:

Modified lunr-search-scripts.html:

  <script src="{{ '/assets/js/lunr/lunr.min.js' }}"></script>
  <script src="{{ '/assets/js/search-data.js' }}"></script>
  {%- unless lang == "en" -%}
    <script src="{{ '/assets/js/lunr/lunr.stemmer.support.min.js' }}"></script>
    <script src="{{ '/assets/js/lunr/lunr.' | append: lang | append: '.min.js' }}"></script>
  {%- endunless %}

It looks more like a linar-search issue and my solution is a bad hack...

@mmistakes
Copy link
Owner

Check your server config. This 100% seems like the issue. It could be sending the wrong MIME type and headers for .json files.

@mmistakes
Copy link
Owner

@metacodez
Copy link
Author

This can very much be the case, before the workaround it also occured directly on the bitbucket hosted website at https://refcodes.bitbucket.io as well as on the reverse-proxied http://www.refcodes.org counterpart. I close this ticket as being solved.

mmistakes added a commit that referenced this issue Feb 17, 2019
adilansari added a commit to adilansari/adilansari.github.io that referenced this issue May 27, 2023
* Remove Disqus comments

* Update README

* Add Twitter

* Update README

* Update README

* Update README

- Add suggested image sizes

* Improve `page.image.path` documentation

* Add migration guide

* Add TOC and change tense

* Remove TOC

* Add custom head and footer includes

- Intentionally left blank to be used as overrides for adding things like favicons to the `<head>` or content to the `<footer>`.

* Document head and footer -custom.html includes

* Update Font Awesome to 5.0.6

* Adjust `blockquote` and `q` styling

* Image asset cleanup

- Rename images
- Remove unused images
- Add image attribution to LICENSE and README

* Guard against Markdown titles

* Add recipes collection of test documents

* Add images to recipes

* Add `{{ content }}` to layouts

* Add `category` and `tag` layouts

* Update layout documentation

- Add `layout: collection`
- Add `layout: category`
- Add `layout: tag`
- Document `entries_layout` to change from list to grid view

* Update migration steps

* Add `search_full_content` to _config.yml

* Add responsive embed helper

* Add table of contents

* Add `page-wrapper` padding back

* Add `.github` files

- Add contributing guidelines
- Add issue template
- Enable stale bot

* Change read more text

* Add Microformats markup

* Add `<a>` styling to `page-sidebar`

* Add Microformats to theme features

* Replace SVGs with Font Awesome icons

* Add table of contents helper

* Document table of contents helper

* Autoprefix CSS

* Add table of contents script

* Update CHANGELOG

* Only show author links when array isn't empty

* Add white-space between social sharing links and comments

* Deprecate v2 readme/installation guide

* Update default _config.yml file

* Edit comments

* Migrate gh-pages branch content to /docs

* Configure theme

* Update default authors and navigation data

* Update default navigation

* Add conditional for `author.name`

* Update theme screenshot

* Add heading

* Change text

* Add link to the CHANGELOG

* Bold text

* Harmonize theme description

* Add primary nav menu toggle

* Autoprefix `animation-name`

* Update screenshot

* Fix typo

* Add Google site verification

* Add layout screenshots

* Add layout screenshots

* Remove duplicate Unreleased notes

* Remove old FontAwesome fonts

* Remove duplicate

* Ignore compiled main.min.js

* Update default config

* Add Google AdSense to /docs site

* Setup remote theme

* Update Ruby gem badge

* Update Git ignore

* Fix Google Analytics conditional

* Release 3.0.1 💎

* Set autofocus on search input

* Update CHANGELOG

* Add links to sample pages and old README

* Bold text

* Update .gitattributes

* Update badges

* Change label

* Enable reading time and MathJax

* Update ISSUE_TEMPLATE.md

* Add `posts_limit` override to `home` layout

* Update `posts_limit` documentation

* Remote theme uses Github repo name

* Update CHANGELOG

* Add `hidden: true` test post

* Update Font Awesome to version 5.0.7

* Added support for collection sorting.

The options sort_by and sort_order can be added in
the front matter. Accepted values for The sort_by
option are the 'title' and 'date', and for the
sort_order option is the 'reverse'.

Example reverse sorting of recipes based on title:

---
title: Recipes
layout: collection
permalink: /recipes/
collection: recipes
show_excerpts: false
sort_by: title
sort_order: reverse
entries_layout: list
---

Signed-off-by: Vangelis Tasoulas <[email protected]>

* Updated README.md with information about collection sorting.

Signed-off-by: Vangelis Tasoulas <[email protected]>

* Fixed typo in _config files.

Signed-off-by: Vangelis Tasoulas <[email protected]>

* Need end-quote for image caption example

Adds missing end quotation mark for image caption in Markdown

* Add note about disabling footer links

Fixes #273

* Fix typo

* Update CHANGELOG

* Release 3.1.0 💎

* Keep search form from resetting when "enter" is hit

* Fix Uncaught TypeError in JavaScript

* Update CHANGELOG

* Update CHANGELOG

* Fix author links

Close #280

* Update CHANGELOG

* Update README

* Before stripping html, add whitespace for excerpts

When excerpts contain html that has implied whitespace (like a <h2> header followed by a <p>, but with no spaces in the text), add some whitespace *before* stripping the html, so that we see "Header paragraph" instead of "Headerparagraph" in the excerpt.

* Update CHANGELOG

* Update Font Awesome to version 5.0.9

https://github.com/FortAwesome/Font-Awesome/blob/master/CHANGELOG.md

* Update issue template

* Update ISSUE_TEMPLATE.md

* Update README.md

* Do not show footer in entry.html if not needed.

If there is no site.read_time or entry.date set, do not show an empty
footer as this only adds some whitespace. In a collection without
excerpts the whitespace between headers is already quite a lot due to
the article tag, so at least, do not add additional unnecessary
whitespace.

Signed-off-by: Vangelis Tasoulas <[email protected]>

* Fix scaled heights for site logo

* Update CHANGELOG

* Update CHANGELOG

* Center hero image for large displays

* Scale `.page-image` to fill parent container

* Update Font Awesome to 5.0.12

* Remove extra spaces

* Add sample `index.md` to root

Fixes #288

* Update CHANGELOG

* Include creation of `navigation.yml` when "starting fresh"

Fixes #270

* Release 3.1.1 💎

* Add theme to config

* Clarified where to customize scss variables

The documentation stated that lines to change variable names should be added to main.scss after @import statements. I tried this and it did not work for me. 

I then added these lines after the import statements and the customization works perfectly. 

According to [this post](https://stackoverflow.com/questions/17089717/how-to-overwrite-scss-variables-when-compiling-to-css) default variables (such as $accent-color) can be overwritten ahead of time. But changing the value of a variable after it has been used will not have any effect on the earlier parts of the CSS where the variable was used. 

Therefore, it seems like variables have to be overwritten after the import statements, and there is no way to overwrite variables that were not declared with !default.

* Update CHANGELOG

* Added spanish translation

* Update CHANGELOG

* Fix filename

* Update GitHub issue templates

* Fix contributing URL

* Correct stylesheet path in documentation

* Update CHANGELOG

* Update LICENSE

* add german translation

* Update CHANGELOG

* Update README.md

* Added french translation

* Typofix

* Update NPM dependencies

* Update CHANGELOG

* Add italian text

* Update CHANGELOG

* Bump year to 2019

* Fix site title and description for page's with a hero image assigned with `page.image`

Close #322

* Add `page.image` example post

* Remove duplicate `h1` headings

Only use set site title as a `h1` on the home page, everywhere else use `<div>` for SEO benefit. Page title should be `h1`.

* Update CHANGELOG

* Fix security issue with seach-data.json by renaming to `.js` and use `relative_url` filter

Ref: mmistakes/so-simple-theme#323 (comment), #326

* Update CHANGELOG

* Release 3.1.2 💎

* Create FUNDING.yml

* Make entire entries and archive items "clickable"

Expand click target to cover entire entry (title, excerpt, date, image, etc.) in home, posts, categories, tags, and collection views.

* Provide accent color to buttons and notices

* Update CHANGELOG

* Relax Jekyll dependency to allow for version 4.0

* Ignore Jekyll cache

* Bump dependencies

* Release 3.1.3 💎

* Update onchange development dependency in package.json

Close #341

* Uglify JavaScript

* Using bundler 2.0.2

* Move all color-related properties into _skin.scss

* Modify the background color of blockquote

* modify background color of blockquote

* Add test navigation links

* Add color to comply with dark skin

* Adjust blockquote background color

* Adjust colors

* Adjust colors

* Update CHANGELOG

* Release 3.2.0 💎

* Add `default.css` skin to config

* Add skin documentation

* Update date

* Update README with `remote_theme` notes

* Add Turkish translates

* Modify the order of taxonomies

* Update CHANGELOG

* Update CHANGELOG

* fix extension names of skins

* Fix

* Update CHANGELOG

* update to bunlder version: 2.1.2

* Add Kannada translation

* Updated changes based on comments

* Add support for MathJax v3

* Update CHANGELOG

* Update CHANGELOG

* Fix rake vulnerability in .gemspec file

* Fix contrast of pagination and copyright text

* Use `rem` units

* Increase readability on small screens

Bump up minimum font-size from `14px` to 16.

* Update CHANGELOG

* Don't hide author avatar on small screens

* Add authors to test site

* Update CHANGELOG

* Bump minimist from 1.2.0 to 1.2.5

Bumps [minimist](https://github.com/substack/minimist) from 1.2.0 to 1.2.5.
- [Release notes](https://github.com/substack/minimist/releases)
- [Commits](https://github.com/substack/minimist/compare/1.2.0...1.2.5)

Signed-off-by: dependabot[bot] <[email protected]>

* Update CHANGELOG.md

* Bump tree-kill from 1.2.1 to 1.2.2

Bumps [tree-kill](https://github.com/pkrumins/node-tree-kill) from 1.2.1 to 1.2.2.
- [Release notes](https://github.com/pkrumins/node-tree-kill/releases)
- [Commits](pkrumins/node-tree-kill@v1.2.1...v1.2.2)

Signed-off-by: dependabot[bot] <[email protected]>

* Delete support.md

* Delete feature_request.md

* Add stale action

* Update `onchange` and `uglify-js` dependencies

* Update FUNDING.yml

* Update FUNDING.yml

* Update README.md

* Update FUNDING.yml

* Delete stale.yml

* Fix security vulenerability with path-parse dependency

* Delete stale.yml

* ignore intellij

* deleting recommended files

* working site except category pages

* major cleanup

* fixed all posts

* grid layout on home

* default theme

---------

Signed-off-by: Vangelis Tasoulas <[email protected]>
Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Michael Rose <[email protected]>
Co-authored-by: Michael Rose <[email protected]>
Co-authored-by: Mike Chelen <[email protected]>
Co-authored-by: Vangelis Tasoulas <[email protected]>
Co-authored-by: Anne Gentle <[email protected]>
Co-authored-by: Joy Payton <[email protected]>
Co-authored-by: Tom <[email protected]>
Co-authored-by: codyolsen <[email protected]>
Co-authored-by: Roger Iyengar <[email protected]>
Co-authored-by: Diego Belmar <[email protected]>
Co-authored-by: Ian Young <[email protected]>
Co-authored-by: hoschi-it <[email protected]>
Co-authored-by: Boris SCHAPIRA <[email protected]>
Co-authored-by: Giovanni Toraldo <[email protected]>
Co-authored-by: Martin Pöhlmann <[email protected]>
Co-authored-by: alxddh <[email protected]>
Co-authored-by: Yusuf DUYAR <[email protected]>
Co-authored-by: sachin <[email protected]>
Co-authored-by: Sachin Shetty <[email protected]>
Co-authored-by: jayanth <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants