Permalink
Browse files

Initial implentation of searching

  • Loading branch information...
Yukaii committed Jul 9, 2017
1 parent a08176c commit bb3a006f690f1ceed8793f9fa0b950f6c043bca9
Showing with 38,632 additions and 247 deletions.
  1. +7 −0 .editorconfig
  2. +5 −1 _assets/css/_layout.scss
  3. +1 −0 _includes/head.html
  4. +1 −0 _includes/post-item.html
  5. +167 −0 _includes/search.html
  6. +7 −0 _includes/search_field.html
  7. +1 −0 _layouts/default.html
  8. +1 −1 _posts/2017-05-04-deploy-redmine-with-puma-nginx-migration-from-mysql-to-postgresql.md
  9. +2 −2 _posts/2017-06-28-windows-unix-like-development-guide-nodejs-ruby.md
  10. +555 −1 _site/about/index.html
  11. +1 −1 ...b49e5adf8b02af421e20c4b1b3ba06f.json → .sprockets-manifest-c91fd71876e335c72a9feaff84430d97.json}
  12. +0 −1 _site/assets/main-04d8319cce89134995ccf323013a5d4fa74724398cceffb75bb8d7a377fe613e.css
  13. +1 −0 _site/assets/main-65485edaba2730e180d11ffc3d0cf530c95d37894310562163b238422187cfc0.css
  14. +555 −1 _site/blog/2014/03/22/stuck-in-checking-battery-status/index.html
  15. +555 −1 _site/blog/2014/03/29/second-attempt-to-implement-threes-1024-2048/index.html
  16. +555 −1 _site/blog/2014/05/04/synergy-causing-windows-explorer-crash/index.html
  17. +555 −1 _site/blog/2014/05/12/troubleshooting-phantosys/index.html
  18. +564 −12 _site/blog/2014/06/28/fifth-to-install-unity3d-on-ubuntu-with-playonlinux/index.html
  19. +555 −1 _site/blog/2015/02/19/campusbooks-com-api-usage/index.html
  20. +555 −1 _site/blog/2015/04/10/seventh-to-write-an-html-email/index.html
  21. +555 −1 _site/blog/2015/04/26/eighth-get-free-heroku-app-does-not-automatically-shut-down/index.html
  22. +555 −1 _site/blog/2015/04/26/nineth-using-itunes-match/index.html
  23. +555 −1 _site/blog/2015/04/26/tenth-chapter-new-york-shi-yijie/index.html
  24. +555 −1 _site/blog/2015/05/03/how-to-write-web-crawler-for-the-first-time-using-ruby/index.html
  25. +555 −1 _site/blog/2015/08/29/12th-ntust-course-helper/index.html
  26. +555 −1 _site/blog/2016/01/23/spex-eshop-amazon/index.html
  27. +555 −1 _site/blog/2016/03/19/taiwan-uniform-invoice-lottery-ruby-gem/index.html
  28. +575 −37 _site/blog/2016/03/26/from-hackpad-to-quip/index.html
  29. +555 −1 _site/blog/2016/04/01/15th-use-aws-codedeploy-deploy-wordpress/index.html
  30. +562 −10 _site/blog/2016/04/07/16th-elk-installation-notes/index.html
  31. +555 −1 _site/blog/2016/06/09/setup-jekyll-on-github-page/index.html
  32. +555 −1 _site/blog/2016/06/22/sublime-atom-vscode-comparison-mid-2016/index.html
  33. +562 −10 _site/blog/2016/07/22/rbenv-fish-and-vscode/index.html
  34. +555 −1 _site/blog/2016/08/12/refocus-from-chrome-address-bar/index.html
  35. +562 −10 _site/blog/2016/08/19/migrate-1password-to-pass/index.html
  36. +555 −1 _site/blog/2016/08/22/blog-new-github-theme/index.html
  37. +563 −11 _site/blog/2016/08/28/rails-girl-7/index.html
  38. +562 −10 _site/blog/2016/09/23/play-android-reverse-engineering-with-jadx/index.html
  39. +555 −1 _site/blog/2016/10/17/contributing-to-open-source/index.html
  40. +555 −1 _site/blog/2016/11/02/use-electron-ipc-to-call-api-from-main-process/index.html
  41. +555 −1 _site/blog/2016/11/12/patching-trello-desktop-electron-app/index.html
  42. +555 −1 _site/blog/2016/12/22/react-native-facebook-native-ads-integration/index.html
  43. +555 −1 _site/blog/2017/01/01/my-2016-summary-as-a-developer/index.html
  44. +555 −1 _site/blog/2017/02/15/how-do-i-watch-anime-in-2017/index.html
  45. +555 −1 _site/blog/2017/02/21/restore-source-code-from-sourcemap-file/index.html
  46. +555 −1 _site/blog/2017/03/29/new-primer-css-github-theme/index.html
  47. +555 −1 _site/blog/2017/04/24/git-cherry-pick/index.html
  48. +569 −22 _site/blog/2017/05/04/deploy-redmine-with-puma-nginx-migration-from-mysql-to-postgresql/index.html
  49. +565 −15 _site/blog/2017/06/28/windows-unix-like-development-guide-nodejs-ruby/index.html
  50. +563 −1 _site/blog/index.html
  51. +4 −4 _site/feed.json
  52. +5 −5 _site/feed.xml
  53. +2 −2 _site/hi-tips.xml
  54. +555 −1 _site/hi-tips/2015-12-11-disable-smart-quotes/index.html
  55. +555 −1 _site/hi-tips/2015-12-12-dotfilesgithubio/index.html
  56. +555 −1 _site/hi-tips/2015-12-19-el-capitan-openssl-ruby-native-gem-not-build-issue/index.html
  57. +555 −1 _site/hi-tips/2015-12-19-tumblr-code-highlighting/index.html
  58. +555 −1 _site/hi-tips/2015-12-19-tumblr-code-highlightingcont/index.html
  59. +565 −15 _site/hi-tips/2015-12-20-my-atom-packages-and-stylesheet/index.html
  60. +555 −1 _site/hi-tips/2015-12-20-rime-im-disable-shift-key-switching-language/index.html
  61. +555 −1 _site/hi-tips/2015-12-22-execute-javascript-function-by-stringname/index.html
  62. +555 −1 _site/hi-tips/2015-12-22-html-encoder/index.html
  63. +555 −1 _site/hi-tips/2015-12-25-find-process-using-particular-port/index.html
  64. +555 −1 _site/hi-tips/2015-12-26-my-simple-way-of-setup-rails-production/index.html
  65. +555 −1 _site/hi-tips/2015-12-27-alfred-theme-reset-after-restarting-on-os-x-el/index.html
  66. +555 −1 _site/hi-tips/2015-12-28-save-activerecord-model-without-validation/index.html
  67. +555 −1 _site/hi-tips/2015-12-28-there-was-a-problem-with-the-editor-vi-not/index.html
  68. +562 −10 _site/hi-tips/2015-12-30-simple-activerecord-filtering-in-controller/index.html
  69. +555 −1 _site/hi-tips/2016-01-01-restore-some-deleted-file-by-git/index.html
  70. +555 −1 _site/hi-tips/2016-01-03-testing-request-through-local-port-listening-with/index.html
  71. +555 −1 _site/hi-tips/2016-01-05-easily-setup-a-packet-monitoring-environment-on/index.html
  72. +555 −1 _site/hi-tips/2016-01-10-use-eventemitter-for-calling-child-component-event/index.html
  73. +555 −1 _site/hi-tips/2016-02-04-css-word-break/index.html
  74. +555 −1 _site/hi-tips/2016-03-18-git-cant-commit-with-vim/index.html
  75. +555 −1 _site/hi-tips/2016-03-20-upgrade-os-x-git-to-274/index.html
  76. +555 −1 _site/hi-tips/2016-03-25-allow-public-accessing-local-rails-server-for/index.html
  77. +555 −1 _site/hi-tips/2016-03-28-hosting-a-mongo-db-instance-on-google-cloud/index.html
  78. +555 −1 _site/hi-tips/2016-03-28-usrbinld-cannot-find-lgmp-while-installing/index.html
  79. +555 −1 _site/hi-tips/2016-04-02-nvm-ls-remote-na-on-ec2-ubuntu/index.html
  80. +563 −11 _site/hi-tips/2017-04-08-setup-primercss-in-vue-js-application/index.html
  81. +555 −1 _site/hi-tips/2017-04-13-rewrite-cookie-cross-subdomain-using-nginx/index.html
  82. +555 −1 _site/hi-tips/index.html
  83. +563 −1 _site/index.html
  84. +555 −1 _site/projects/index.html
  85. +1 −0 blog/index.html
  86. +1 −0 index.html
View
@@ -0,0 +1,7 @@
root = true
[*.html]
insert_final_newline = false
[_includes/post-item.html]
insert_final_newline = false
View
@@ -197,7 +197,11 @@
/**
* Page content
*/
.page-content {
.home {
padding: $spacing-unit / 4 * 3 0;
}
.post {
padding: $spacing-unit 0;
}
View
@@ -31,5 +31,6 @@
<link rel="alternate" type="application/rss+xml" title="{{ site.title }}" href="{{ "/feed.xml" | prepend: site.baseurl | prepend: site.url }}">
<script src="{{ 'turbolinks.js' | asset_path }}" type="text/javascript" charset="utf-8" defer></script>
<script src="https://ajax.googleapis.com/ajax/libs/webfont/1.6.16/webfont.js" defer></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lunr.js/2.1.1/lunr.min.js" integrity="sha256-zhOWzIBi18E7Gu3HoaHA5g4HDXPMdu++IrFs0F42o7c=" crossorigin="anonymous"></script>
<script src="{{ 'webfont.js' | asset_path }}" type="text/javascript" charset="utf-8" defer></script>
</head>
View
@@ -0,0 +1 @@
<div class="menu-item"><h4><a href="{{ include.url | prepend: site.baseurl }}">{{ include.title }}</a><a href="{{ include.url | prepend: site.baseurl | append: '#disqus_thread' }}" style="display: inline-block; float: right;" class="comments-link"> {% octicon comment %}<span class="disqus-comment-count" data-disqus-identifier="{{ include.url | prepend: site.url }}"></span></a></h4><div class="post-meta">{{ include.date | date: "%b %-d, %Y" }}</div></div>
View
@@ -0,0 +1,167 @@
<script data-turbolinks-eval="false">
/* nice guide from https://learn.cloudcannon.com/jekyll/jekyll-search-using-lunr-js/ */
var pageLoaded = false;
(function() {
var store = {
{% for post in site.posts %}
"{{ post.url | slugify }}": {
"title": "{{ post.title | xml_escape }}",
"url": "{{ post.url | xml_escape }}",
"author": "{{ post.author | xml_escape }}",
"category": "{{ post.category | xml_escape }}",
"content": {{ post.content | strip_html | strip_newlines | jsonify }},
"url": "{{ post.url | xml_escape }}",
"date": "{{ post.date | date: "%b %-d, %Y" }}"
}
{% unless forloop.last %},{% endunless %}
{% endfor %}
};
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split('&');
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split('=');
if (pair[0] === variable) {
return decodeURIComponent(pair[1].replace(/\+/g, '%20'));
}
}
}
function displaySearchResults(results, store) {
var elements = []
for (var i = 0; i < results.length; i++) {
var item = store[results[i].ref]
var string = '{% include post-item.html url='' title='' %}'
var div = document.createElement('div')
div.innerHTML = string;
var element = div.firstChild
/* build post data */
var anchors = element.querySelectorAll('a')
for (var j = 0; j < anchors.length; j++) {
// prepend link
anchors[j].setAttribute('href', item.url + anchors[j].getAttribute('href'))
}
// add title
var title = element.querySelector('h4 a')
title.innerHTML = item.title
var postMeta = element.querySelector('.post-meta')
postMeta.innerHTML = item.date
elements.push(element)
}
/* build search results */
var searchList = document.createElement('nav')
searchList.className = 'menu centered search-list'
for (var i = 0; i < elements.length; i++) { searchList.appendChild(elements[i]) }
// clean up old searchlist
var oldSearchList = document.querySelector('.menu.centered.search-list')
if (oldSearchList) {
oldSearchList.remove()
}
var oldList = document.querySelector('.menu.centered')
oldList.style.display = 'none'
var homeContainer = document.querySelector('.home')
homeContainer.insertBefore(searchList, oldList)
}
function search () {
console.log('call search')
var inputField = document.querySelector('#post-search-form #post-search')
var searchTerm
if (pageLoaded) {
if (inputField && inputField.value) {
searchTerm = inputField.value
if (history.pushState) {
var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + '?query=' + searchTerm;
window.history.pushState({path:newurl},'',newurl);
}
} else {
/* cleanup history */
if (history.pushState) {
var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname;
window.history.pushState({path:newurl},'',newurl);
}
}
} else {
searchTerm = getQueryVariable('query');
pageLoaded = true
}
if (searchTerm) {
document.querySelector('#post-search-form #post-search').setAttribute("value", searchTerm);
// Initalize lunr with the fields it will be searching on. I've given title
// a boost of 10 to indicate matches on this field are more important.
var idx = lunr(function () {
this.field('id');
this.field('title', { boost: 10 });
this.field('author');
this.field('category');
this.field('content');
this.field('url');
this.field('date');
for (var key in store) { // Add the data to lunr
this.add({
'id': key,
'title': store[key].title,
'author': store[key].author,
'category': store[key].category,
'content': store[key].content,
'url': store[key].url,
'date': store[key].date,
});
}
});
var results = idx.search(searchTerm); // Get lunr to perform a search
displaySearchResults(results, store); // We'll write this in the next section
} else {
// clean up
var searchList = document.querySelector('.menu.centered.search-list')
if (searchList) {
searchList.remove()
}
var oldList = document.querySelector('.menu.centered')
if (oldList) {
oldList.style.display = 'inherit'
}
if (history.pushState) {
var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname;
window.history.replaceState({path:newurl},'',newurl);
}
}
}
/* apply search */
if (!pageLoaded) search()
var searchForm = document.getElementById('post-search-form')
if (searchForm) {
searchForm.addEventListener('submit', function (e) {
e.preventDefault()
search()
})
}
})()
</script>
@@ -0,0 +1,7 @@
<div class="container form-container" style="padding: .5em 0;">
<form accept-charset="UTF-8" class="subnav-search container" id="post-search-form" style="display: inline-block; margin-left: 0px; margin-bottom: 5px;">
<input aria-label="Search Post" class="form-control form-control subnav-search-input input-contrast" id="post-search" name="query" placeholder="Search posts" type="text" >
{% octicon search class:"subnav-search-icon" style:"fill: #c6cbd1;" %}
<button class="btn btn-primary">Search</button>
</form>
</div>
View
@@ -16,6 +16,7 @@
{% include footer.html %}
<script id="dsq-count-scr" src="//dailyoops.disqus.com/count.js" async></script>
{% include search.html %}
</body>
</html>
@@ -129,7 +129,7 @@ psql -U redmine -d redmine -W
- `config/database.yml`
- `config/configuration.yml`
從 MySQL 搬家到 Postgres 的部分,因為都是同一個 App,Redmine 版本也只是小升沒有大型 migration,我直接利用[`yaml_db`](https://github.com/yamldb/yaml_db) 套件,把資料庫 dump 出來成 yaml,然後在 load 就行了 :heart: 可以參考 [`yaml_db`](https://github.com/yamldb/yaml_db) 套件 GitHub 說明。
從 MySQL 搬家到 Postgres 的部分,因為都是同一個 App,Redmine 版本也只是小升沒有大型 migration,我直接利用[`yaml_db`](https://github.com/yamldb/yaml_db) 套件,把資料庫 dump 出來成 yaml,然後在 load 就行了 😍 可以參考 [`yaml_db`](https://github.com/yamldb/yaml_db) 套件 GitHub 說明。
先跑 `RAILS_ENV=production bundle exec rake db:setup` 建立資料庫,然後在 `bundle exec rake db:data:load` 把檔案載入進來。
@@ -84,7 +84,7 @@ sudo usermod -G GROUP_NAME smbuser
看論壇上的討論([stackoverflow](https://stackoverflow.com/questions/22842920/how-to-edit-code-in-a-docker-container-in-development)、[forum](https://forums.docker.com/t/best-practices-for-getting-code-into-a-container-git-clone-vs-copy-vs-data-container/4077))大都搭配 data container/volumn mounting/shared drive 的方式來弄,不過你也知道 NTFS 一扯到 symlink [目前還是沒戲兒](https://github.com/docker/for-win/issues/109)。
另一種方法是用 [COPY](http://blog.cloud66.com/how-to-get-code-into-a-docker-container/) 來弄,不過跟 Windows 相容性如何,那畫面太美我不敢想 :joy: 所以囉
另一種方法是用 [COPY](http://blog.cloud66.com/how-to-get-code-into-a-docker-container/) 來弄,不過跟 Windows 相容性如何,那畫面太美我不敢想 😂 所以囉
## 結論
@@ -94,7 +94,7 @@ sudo usermod -G GROUP_NAME smbuser
![VSCode](http://i.imgur.com/G09U4RQ.png)
本篇文章就是在 Windows 下的 VSCode 編輯 Markdown、配上 Hyper-V 下的 Ubuntu 使用 Jekyll 生成的。讚讚 :heart:
本篇文章就是在 Windows 下的 VSCode 編輯 Markdown、配上 Hyper-V 下的 Ubuntu 使用 Jekyll 生成的。讚讚 😍
主題是 [Kary Light](https://github.com/karyfoundation/kf-theme-vscode) 配上 [Inziu Iosevka](https://be5invis.github.io/Iosevka/inziu.html),Windows 跟這套字體真是絕配!
Oops, something went wrong.

0 comments on commit bb3a006

Please sign in to comment.