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

Can't use Google Custom Search Engine - wrong tag parsing #2616

Closed
chyla opened this issue Jan 6, 2017 · 2 comments
Closed

Can't use Google Custom Search Engine - wrong tag parsing #2616

chyla opened this issue Jan 6, 2017 · 2 comments

Comments

@chyla
Copy link

chyla commented Jan 6, 2017

Google CSE requires to add to the page the following code:

<script>
  (function() {
    var cx = 'XXXXXXXX';
    var gcse = document.createElement('script');
    gcse.type = 'text/javascript';
    gcse.async = true;
    gcse.src = 'https://cse.google.com/cse.js?cx=' + cx;
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(gcse, s);
  })();
</script>
<gcse:search></gcse:search>

The problem exists in line gcse:search</gcse:search>. Nikola (mako?) is removing first part (gcse:), so the output code is wrong and it doesn't work.

Output code after nikola processing:

<script>
  (function() {
    var cx = 'XXXXXXXX';
    var gcse = document.createElement('script');
    gcse.type = 'text/javascript';
    gcse.async = true;
    gcse.src = 'https://cse.google.com/cse.js?cx=' + cx;
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(gcse, s);
  })();
</script>
<search></search>

Workaround:

<script>
  (function() {
    var cx = 'XXXXXXXX';
    var gcse = document.createElement('script');
    gcse.type = 'text/javascript';
    gcse.async = true;
    gcse.src = 'https://cse.google.com/cse.js?cx=' + cx;
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(gcse, s);
  })();
</script>
<script>
    document.write("<gcse:search></gcse:search>");
</script>

Additional info:
nikola version: v7.6.4
default install,
template file

@da2x
Copy link
Contributor

da2x commented Jan 6, 2017

The code you were given by Google CSE isn’t really meant to be used with any tools that process XML or HTML.

Here’s the solution: https://developers.google.com/custom-search/docs/element#html5

I can’t understand why Google haven’t made their HTML5 compatible code snippet the default yet. This keeps popping up all over the web causing problems for different tools. I think Google maybe don’t want to encourage websites to use CSEs anymore. It’s a service that is being treated a bit like FeedBurner these days.

@da2x da2x closed this as completed Jan 6, 2017
@Kwpolska
Copy link
Member

Kwpolska commented Jan 7, 2017

Also, please upgrade Nikola, because v7.6.4 is woefully out of date and unsupported. Complain to Debian and use a virtualenv.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants