Getting search bar to work with Hexo-Algolia - algolia

There's some issue with the old algolia account so I've to create a new one, with new App ID and API key etc., for testing with updated contents but now my search-bar wouldn't work.
So what's in the current _config.yml file is as followed:
algolia:
en:
api_key: c3d5d4c995b5e0c2ffb5623900279a66
index_name: hexo
zh-cn:
api_key: cdea7d4e47d84f6145b77e7f68689f35
index_name: hexo_zh-cn
and it's actually working fine with search bar showing. Just that the search-contents are wrong.
So with my new set of ID and API keys, I tried to simply replace the above api_key with the new one and running the hexo algolia command, the following error was shown:
ERROR [Algolia] Please set a `HEXO_ALGOLIA_INDEXING_KEY` environment variable to enable content indexing.
ERROR >> Read https://npmjs.com/hexo-algolia#api-key for more informations.
I followed the documentation for algolia, with the following amendment to the _config.yml and the hexo algolia command works like a charm:
algolia:
applicationID: CDWIP9PSJ7
apiKey: 218de3a558ce35814a7ac580345770a5
indexName: hexo
However, here's come the issue, my original search bar wouldn't appear anymore :/ I've noticed it's probably due to the missing en: & zh-cn:, but when I added those in, my hexo-algolia command wouldn't work again with the following error:
FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html
AlgoliaSearchError: Please provide an application ID. Usage: algoliasearch(applicationID, apiKey, opts)
So now I'm puzzled, how is the old code able to work without the Application ID? and comes to the question, is there a version upgrade to Algolia and therefore an update to the format as well?
I'm actually more concern on how to get the search bar to appear again but I believe the above question can hopefully lead me to solve the issue. But for those who happen to know, help is greatly appreciated!
I believe the "search-bar with algolia script" connection is related to the after_footer.swig file with the following original code:
<!-- Algolia -->
{% if config.algolia[page.lang] %}
<script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.js"></script>
<script type="text/javascript">
document.getElementById('search-input-wrap').classList.add('on');
docsearch({
apiKey: '{{ config.algolia[page.lang].api_key }}',
indexName: '{{ config.algolia[page.lang].index_name }}',
inputSelector: '#search-input'
});
</script>
{% endif %}
Much thanks in advance!

Related

Craft CMS plugin AssetBundle Causeing Craft.js Error in Backend

Plugin routes the following url in the admin area to a controller.
url: /admin/custom_route
The controller loads the plugin asset bundle that is CpAssets::class dependent & loads the twig template everything loads but browser console gives an error for Craft.js that Craft is not defined inside the Jquery exenteded plugin function. Where Craft.js & Craft.min.js are both being loaded when only one of them should be.
Been looking at the yii functionality but I'm at a loss.
Solution for anyone who else who is confused with the same problem.
In your template.twig you need to add head tags & call the head function this eliminates the Craft.js error.
<head>
{{ head() }}
</head>
I found the solution by looking at src/web/assets/cp/CpAsset.php where at line 98 - 103 it defines the missing js Craft object.
// Define the Craft object
$craftJson = Json::encode($this->_craftData(), JSON_UNESCAPED_UNICODE);
$js = <<<JS
window.Craft = {$craftJson};
JS;
$view->registerJs($js, View::POS_HEAD);
Where View::POS_HEAD defines the position in the document where the script is loaded according to the yii documentation. Just calling
{{ head() }}
Will not work it need to be within the head element tags of the document.

PrestaShop translation in email theme

I created a specific theme for PrestaShop in mails > themes and I would like to add a sentence in the components > footer.html.twig
In Classic theme I saw this code:
{{ '{shop_name} powered by PrestaShop™'|trans({'{prestashop_url}': 'https://www.prestashop.com/?utm_source=marchandprestashop&utm_medium=e-mail=utm_campaign=footer_1-7'}, 'Emails.Body', locale)|raw }}
So I tried to use trans() like this:
{{ 'My sentence'|trans({}, 'Emails.Body', locale)|raw }}
But I've got no clue where I'm supposed to translate it now! I looked in back-office translations but couldn't find it anywhere.
Some help will really be appreciated! Thanks :)
You can try to insert a new row into a PREFIX_translation table in your database.
Domain should be typed without a dot, like this: EmailsBody.
Unfortunately translations in 1.7 are still a little tricky these days :(
Remember about clearing cache after adding new row into DB.

Jekyll on Github suddenly do not work because of 'nil' date

Well, I swear I changed no setting at all.
I setup my Jekyll blog, and it did work before.
Every time I want to write something new, I just copy and old post file, rename it to the current date and modify the content within it.
But just one day, after I push my new content to Github, I received an email, noticing me that
The page build failed for the master branch with the following error:
The value 'nil' was passed to a date-related filter that expects valid dates in /_layouts/post.html or one of its layouts. For more information, see https://help.github.com/articles/page-build-failed-date-is-not-a-valid-datetime/.
For information on troubleshooting Jekyll see:
https://help.github.com/articles/troubleshooting-jekyll-builds
First, I did not modify /_layouts/post.html. Second, I do not use date info in YAML, because Jekyll already uses the strong name requirement like YY-MM-DD-title.md.
I am just some guy who wants to write something fun but knows little about IT tech. I searched the Jekyll doc, and read the post on StackOverflow like below:
Invalid date while building on Github Pages
But as my post.html file content is different from that post, I do not know what I can do.
I built it on my Mac with bundle exec Jekyll build, it just shows the same information as the email
$ bundle exec jekyll build
Configuration file: > /Users/zhanglidong/Documents/ASyncFiles/jetorz.github.io/_config.yml
Source: /Users/zhanglidong/Documents/ASyncFiles/jetorz.github.io
Destination: > /Users/zhanglidong/Documents/ASyncFiles/jetorz.github.io/_site
Incremental build: disabled. Enable with --incremental
Generating...
Liquid Exception: Invalid Date: 'nil' is not a valid datetime. in /_layouts/post.html
ERROR: YOUR SITE COULD NOT BE BUILT:
------------------------------------
Invalid Date: 'nil' is not a valid datetime.
My GitHub repo: https://github.com/jetorz/jetorz.github.io
My jekyll blog: https://jetorz.github.io/
How can I fix it? Any one who wants to help the pity me? :(
Like answer above suggested,
I rechecked the link I provided:
Invalid date while building on Github Pages
There is and if block outside the <time> part.
I do not know much about Liquid,
But I think it worth trying.
So I add this if to my post.html like below
{% if page.date %}
<time datetime="{{ page.date | date_to_xmlschema }}" itemprop="datePublished">
{% assign date_format = site.minima.date_format | default: "%b %-d, %Y" %}
{{ page.date | date: date_format }}
</time>
{% endif %}
I do not know exactly what it is about,
but It does work :)
Now again I can post my blog.

Getting the emberjs starter-kit to work with coffeescript

i'm trying to get the starter-kit example of ember.js to work directly with an app written in coffeescript (with the use of http://coffeescript.org/extras/coffee-script.js).
I want to use this in an development environment, without the need to convert the coffescript to javascript first (manually or with tools like jitter).
Basically i just replaced the line
<script src="js/app.js"></script>
with the lines
<script src="js/libs/coffee-script-1.3.3.min.js"></script>
<script type="text/coffeescript" src="coffee/app.coffee"></script>
in the index.html
All changes i've made can be found in my fork on github at https://github.com/GordonSchmidt/starter-kit
The coffescript itself seems to be fine, because when i convert it to javascript first the starter-kit application works with this javascript. But when i use the coffeescript directly it throws the error "assertion failed: Unable to find view at path 'App.MyView'" in line 45 of ember-0.9.8.1.js. The coffee-script.js all by itself seems to work as well (see demo.html). So it has to be a conflict between ember.js and coffee-script.js.
But I'm not able to find this error. Can someone please point me in the right direction?
from coffeescript.org
The usual caveats about CoffeeScript apply — your inline scripts will
run within a closure wrapper, so if you want to expose global
variables or functions, attach them to the window object.
your coffeescript should look something like this:
<script type="text/coffeescript">
window.App = App = Em.Application.create()
App.MyView = Em.View.extend(
mouseDown: -> window.alert "hello world!"
)​
</script>
see here for a fiddle

Lazy load github gist files to display source code on the website

I have a couple of gists which I need to include in a website post to showcase the source code. Currently, I'm inlining each of the multiple gists at various places in the HTML with script tags, however, this would be a blocking call. So, is there a way to dynamically load the gists and paste it specific points in time.
I tried something like below :-
<html>
<body>
<div id="bookmarklet_1.js"></div>
<div id="bookmarklet_2.js"></div>
<div id="bookmarklet_3.js"></div>
var scriptMap = {'bookmarklet_1.js' : 'https://gist.github.com/892232.js?file=bookmarklet_1.js',
'bookmarklet_2.js' : 'https://gist.github.com/892234.js?file=bookmarklet_2.js',
'bookmarklet_3.js' : 'https://gist.github.com/892236.js?file=bookmarklet_3.js'};
var s, scr, holder;
for(s in scriptMap){
holder = document.getElementById(s);
scr= document.createElement('script');
scr.type= 'text/javascript';
scr.src= scriptMap[s];
holder.appendChild(scr);
}
</script>
</body>
</html>
The above didn't work for me, it seems that each script is doing a document.write internally to write the CSS and soure code. Has anyone tried this before or got it working ?
I started a project exactly for this purpose. Dynamically-embedded Gists
Try it now: http://urlspoiler.herokuapp.com/gists?id=992729
Use the above url as the src of a dynamically-created iframe, or add &format=html to get the Gist html snippet via ajax, then put it anywhere you want. (The gist in the above url also happens to be the documentation for how to use this project.)
I myself wanted to do exactly the same thing (with the addition of even removing the default gist style link) - ended up building a "generic" script loader that handles document.write calls :
https://github.com/kares/script.js
Here's how one can use it for embedding gists (and pasties) :
https://github.com/kares/script.js/blob/master/examples/gistsAndPasties.html
You can now get the HTML + CSS directly using JSONP.
I wrote a fuller answer in response to this question, but the key is that you can get the HTML + CSS using JSONP.
For example: https://gist.github.com/anonymous/5446989.json?callback=callback12345
callback12345({
"description": "Function to load a Gist without an iframe",
"public": true,
...
"div": <HTML code>,
"stylesheet": <URL of CSS file>
})