From 566a103c9a1fd9d25b68ada6ca3d72cd73f3ad07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Fernando=20S=C3=A1nchez?= Date: Fri, 11 Jan 2019 16:03:17 +0100 Subject: [PATCH] Add search --- config.toml | 3 +- content/about.md | 98 ------------------ content/page/.#todo2.md | 1 + content/page/about.md | 9 ++ content/page/todo.md | 30 ++++++ content/{projects.md => project/index.md} | 8 +- content/project/index.rst | 24 ----- content/project/otro.md | 7 ++ content/search.md | 59 +++++++++++ content/todo.md | 39 ------- themes/balkian/layouts/_default/baseof.html | 5 + themes/balkian/layouts/_default/index.json | 5 + themes/balkian/layouts/_default/terms.html | 2 +- themes/balkian/layouts/page/search.html | 30 ++++++ themes/balkian/static/css/main.css | 18 +++- themes/balkian/static/js/search.js | 109 ++++++++++++++++++++ 16 files changed, 279 insertions(+), 168 deletions(-) delete mode 100644 content/about.md create mode 120000 content/page/.#todo2.md create mode 100644 content/page/about.md create mode 100644 content/page/todo.md rename content/{projects.md => project/index.md} (75%) delete mode 100644 content/project/index.rst create mode 100644 content/project/otro.md create mode 100644 content/search.md delete mode 100644 content/todo.md create mode 100644 themes/balkian/layouts/_default/index.json create mode 100644 themes/balkian/layouts/page/search.html create mode 100644 themes/balkian/static/js/search.js diff --git a/config.toml b/config.toml index c48c15c..285d209 100644 --- a/config.toml +++ b/config.toml @@ -5,7 +5,6 @@ theme = "balkian" preserveTaxonomyNames = true disqusShortname = "balkian" googleAnalytics = "" -SectionPagesMenu = "main" Paginate = 5 pygmentsCodeFences = true pygmentsOptions = "linenos=table" @@ -13,6 +12,8 @@ summaryLength = 50 relativeURLs = true copyright = "This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License." +[outputs] + home = ["HTML", "RSS", "JSON"] [taxonomies] category = "categories" diff --git a/content/about.md b/content/about.md deleted file mode 100644 index 2d2732d..0000000 --- a/content/about.md +++ /dev/null @@ -1,98 +0,0 @@ -+++ -title = "About" -date = "2017-02-24" -menu = ["main"] -+++ - -Hi! - -My name is Fernando. I'm a researcher and developer from Madrid, Spain. - - ---- - - -
- -
- Linux lover - Android dev - GitHub user - StackExchange fan - Music lover - Movie fan - Always on IM - Always on a PC - Occassional writter - Night owl - CLI user - Linguist wannabe - Love to code - Keen reader - Quotes on demand -
-
diff --git a/content/page/.#todo2.md b/content/page/.#todo2.md new file mode 120000 index 0000000..56726f0 --- /dev/null +++ b/content/page/.#todo2.md @@ -0,0 +1 @@ +j@panther.18281:1546943267 \ No newline at end of file diff --git a/content/page/about.md b/content/page/about.md new file mode 100644 index 0000000..7211edf --- /dev/null +++ b/content/page/about.md @@ -0,0 +1,9 @@ ++++ +title = "About" +date = "2017-02-24" +menu = ["main"] ++++ + +Hi! + +My name is Fernando. I'm a researcher and developer from Madrid, Spain. diff --git a/content/page/todo.md b/content/page/todo.md new file mode 100644 index 0000000..3f602f3 --- /dev/null +++ b/content/page/todo.md @@ -0,0 +1,30 @@ +--- +title: To-do +menu: main + +--- + +### PhD +- [x] Write my first workshop paper as main author +- [x] Write my first journal paper +- [x] Write my first book chapter +- [x] Chair a W3C Community Group +- [ ] Collaborate in a W3C recommendation +- [ ] Become a doctor! + +### Technical +- [x] Write a NodeJS App. Maia [See [ISSUES](http://github.com/gsi-upm/maia/issues)] +- [x] Write my first Django Application +- [ ] Develop a distributed LibP2P golang application +- [ ] Github repo with +100 stars + +### Languages +- [x] English +- [ ] Chinese +- [ ] Greek +- [ ] German +- [ ] Esperanto + +### Personal +- [x] Run a 10k +- [ ] Blog regularly for a year diff --git a/content/projects.md b/content/project/index.md similarity index 75% rename from content/projects.md rename to content/project/index.md index 0dd3381..4028b80 100644 --- a/content/projects.md +++ b/content/project/index.md @@ -6,15 +6,17 @@ title: Index of projects Ongoing Projects ================ +* [Senpy](http://senpy.readthedocs.io): a framework for semantic sentiment and emotion analysis services. +* [Soil](http://soilsim.readthedocs.io): an agent-based simulator for social networks based on nx-sim and networkx. * [Onyx](http://gsi.dit.upm.es/ontologies/onyx): an ontology for emotion analysis that includes concepts from W3C's provenance. -* [Marl](http://gsi.dit.upm.es/ontologies/marl): I updated this ontology, originally created by Adam Westerski, to make it compatible with the W3C's provenance ontology. Past Projects ============= +* [Marl](http://gsi.dit.upm.es/ontologies/marl): I updated this ontology, originally created by Adam Westerski, to make it compatible with the W3C's provenance ontology. * [Hermes](http://github.com/balkian/hermes): one of my first projects, developed together with David Pérez as the special custom assignment in one of our courses. Hermes is an affective bot designed to mimic the behavour of humans. It included a plug-in system for its sensors and actuators. The information from its sensors changed its emotional state, which was shown via its actuators. Among others, it could fetch inforation from Twitter or its host system and change the expressions of an external Face made with servo motors or speak via its Text-To-Speech software. For instance, it could detect it was running out of battery, showing a sad face and sending an alerting tweet. You can see it in action in these two youtube videos: [Part 1](http://www.youtube.com/watch?v=KnEYahPD9z4) and [Part 2](http://www.youtube.com/watch?v=lQZldCTPEJc). -* [EESTEC.net](http://github.com/eestec/eestec.portal): the Plone based official portal of EESTEC. I fixed some bugs and implemented basic features. It's still an ongoing project. * [Maia](http://github.com/gsi-upm/maia): the Modular Architecture for Intelligent Agents is an evented agent architecture that aims to update the classical frameworks for intelligent agents with the concepts emerged from the Live Web. +* [EESTEC.net](http://github.com/eestec/eestec.portal): the Plone based official portal of EESTEC. It has been my first and only experience with Plone. I fixed some bugs and implemented basic features. -For more information, checl my [complete list of public repositories in Github. +For more information, check my list of public repositories in Github. diff --git a/content/project/index.rst b/content/project/index.rst deleted file mode 100644 index 8c4a895..0000000 --- a/content/project/index.rst +++ /dev/null @@ -1,24 +0,0 @@ ---- -title: Index of projects - ---- - -Ongoing Projects -================ - -* `Onyx `_: an ontology for emotion analysis that includes concepts from W3C's provenance. -* `Marl `_: I updated this ontology, originally created by Adam Westerski, to make it compatible with the W3C's provenance ontology. - - -Past Projects -============= - -* `Hermes `_: one of my first projects, developed together with David Pérez as the special custom assignment in one of our courses. Hermes is an affective bot designed to mimic the behavour of humans. It included a plug-in system for its sensors and actuators. The information from its sensors changed its emotional state, which was shown via its actuators. Among others, it could fetch inforation from Twitter or its host system and change the expressions of an external Face made with servo motors or speak via its Text-To-Speech software. For instance, it could detect it was running out of battery, showing a sad face and sending an alerting tweet. You can see it in action in these two youtube videos: `Part 1 `_ and `Part 2 `_. -* `EESTEC.net `_: the Plone based official portal of EESTEC. I fixed some bugs and implemented basic features. It's still an ongoing project. -* `Maia `_: the Modular Architecture for Intelligent Agents is an evented agent architecture that aims to update the classical frameworks for intelligent agents with the concepts emerged from the Live Web. - -For more information, checl my [complete list of public repositories in |github|. - -.. |github| raw:: html - - Github diff --git a/content/project/otro.md b/content/project/otro.md new file mode 100644 index 0000000..bc03406 --- /dev/null +++ b/content/project/otro.md @@ -0,0 +1,7 @@ +--- +title: just a test +type: page +--- + + +It does nothing diff --git a/content/search.md b/content/search.md new file mode 100644 index 0000000..0982340 --- /dev/null +++ b/content/search.md @@ -0,0 +1,59 @@ +--- +title: "Search Results" +layout: "search" +sitemap: + priority : 0.1 +--- + + +This file exists solely to respond to /search URL with the related `search` layout template. + +No content shown here is rendered, all content is based in the template layouts/page/search.html + +Setting a very low sitemap priority will tell search engines this is not important content. + +This implementation uses Fusejs, jquery and mark.js + + +## Initial setup + +Search depends on additional output content type of JSON in config.toml +\``` +[outputs] + home = ["HTML", "JSON"] +\``` + +## Searching additional fileds + +To search additional fields defined in front matter, you must add it in 2 places. + +### Edit layouts/_default/index.JSON +This exposes the values in /index.json +i.e. add `category` +\``` +... + "contents":{{ .Content | plainify | jsonify }} + {{ if .Params.tags }}, + "tags":{{ .Params.tags | jsonify }}{{end}}, + "categories" : {{ .Params.categories | jsonify }}, +... +\``` + +### Edit fuse.js options to Search +`static/js/search.js` +\``` +keys: [ + "title", + "contents", + "tags", + "categories" +] +\``` + +
+ diff --git a/content/todo.md b/content/todo.md deleted file mode 100644 index 6042617..0000000 --- a/content/todo.md +++ /dev/null @@ -1,39 +0,0 @@ ---- -title: To-Do - ---- - -

Things To Do

-This is intended as my public "todo.txt". Both to keep it accessible and to feel ashamed of the many things I leave undone: -
    -
  • PhD -
      -
    • Write my first workshop paper as main author
    • -
    • Write my first journal paper
    • -
    • Become a doctor!
    • -
    -
  • -
  • Technical -
      -
    • Write a NodeJS App. Maia [See ISSUES]
    • -
    • Write my first Django Application
    • -
    • Win my first Hackathon
    • -
    • Github repo with +100 stars
    • -
    -
  • -
  • Languages -
      -
    • English
    • -
    • Chinese
    • -
    • Greek
    • -
    • German
    • -
    • Esperanto
    • -
    -
  • -
  • Personal -
      -
    • Run a 10k
    • -
    • Blog regularly for a year
    • -
    -
  • -
diff --git a/themes/balkian/layouts/_default/baseof.html b/themes/balkian/layouts/_default/baseof.html index ec535ee..f947099 100644 --- a/themes/balkian/layouts/_default/baseof.html +++ b/themes/balkian/layouts/_default/baseof.html @@ -37,6 +37,9 @@
  • CV
  • +
  • + +
  • @@ -68,5 +71,7 @@ + {{ block "footerfiles" . }} + {{ end }} diff --git a/themes/balkian/layouts/_default/index.json b/themes/balkian/layouts/_default/index.json new file mode 100644 index 0000000..c93f805 --- /dev/null +++ b/themes/balkian/layouts/_default/index.json @@ -0,0 +1,5 @@ +{{- $.Scratch.Add "index" slice -}} +{{- range .Site.RegularPages -}} + {{- $.Scratch.Add "index" (dict "title" .Title "tags" .Params.tags "categories" .Params.categories "contents" .Plain "permalink" .Permalink) -}} +{{- end -}} +{{- $.Scratch.Get "index" | jsonify -}} diff --git a/themes/balkian/layouts/_default/terms.html b/themes/balkian/layouts/_default/terms.html index a9cda46..ed168ff 100644 --- a/themes/balkian/layouts/_default/terms.html +++ b/themes/balkian/layouts/_default/terms.html @@ -1,5 +1,5 @@ {{ define "content" }} -

    {{ .Data.Plural | humanize}}

    +

    {{ .Data.Plural | humanize}}

    {{ $data := .Data }} {{ $total := .Site.Pages | len}} diff --git a/themes/balkian/layouts/page/search.html b/themes/balkian/layouts/page/search.html new file mode 100644 index 0000000..5d55c89 --- /dev/null +++ b/themes/balkian/layouts/page/search.html @@ -0,0 +1,30 @@ +{{ define "footerfiles" }} + + + + +{{ end }} +{{ define "content" }} +
    +
    + +
    +

    Matching pages

    +
    +
    +
    + + +{{ end }} diff --git a/themes/balkian/static/css/main.css b/themes/balkian/static/css/main.css index 7c2afb6..c8d63ed 100755 --- a/themes/balkian/static/css/main.css +++ b/themes/balkian/static/css/main.css @@ -385,9 +385,8 @@ footer a:hover { border: 0; } -.todo { +.todo , .task-list { list-style-type: none; - font-weight: bold; } .todo ul { @@ -805,3 +804,18 @@ pre { margin: 0; padding: 1em; } + +.search { + width: 100%; + padding: 0; +} + +.searchTerm { + padding: 0.5em 1em; +} + +.search > * { + vertical-align: middle; + margin:0; + height: 100%; +} diff --git a/themes/balkian/static/js/search.js b/themes/balkian/static/js/search.js new file mode 100644 index 0000000..a80a8b8 --- /dev/null +++ b/themes/balkian/static/js/search.js @@ -0,0 +1,109 @@ + +summaryInclude=60; +var fuseOptions = { + shouldSort: true, + includeMatches: true, + threshold: 0.0, + tokenize:true, + location: 0, + distance: 100, + maxPatternLength: 32, + minMatchCharLength: 1, + keys: [ + {name:"title",weight:0.8}, + {name:"contents",weight:0.5}, + {name:"tags",weight:0.3}, + {name:"categories",weight:0.3} + ] +}; + + +var searchQuery = param("s"); +if(searchQuery){ + $("#search-query").val(searchQuery); + executeSearch(searchQuery); +}else { + $('#search-results').append("

    Please enter a word or phrase above

    "); +} + + + +function executeSearch(searchQuery){ + $.getJSON( "/index.json", function( data ) { + var pages = data; + var fuse = new Fuse(pages, fuseOptions); + var result = fuse.search(searchQuery); + console.log({"matches":result}); + if(result.length > 0){ + populateResults(result); + }else{ + $('#search-results').append("

    No matches found

    "); + } + }); +} + +function populateResults(result){ + $.each(result,function(key,value){ + var contents= value.item.contents; + var snippet = ""; + var snippetHighlights=[]; + var tags =[]; + if( fuseOptions.tokenize ){ + snippetHighlights.push(searchQuery); + }else{ + $.each(value.matches,function(matchKey,mvalue){ + if(mvalue.key == "tags" || mvalue.key == "categories" ){ + snippetHighlights.push(mvalue.value); + }else if(mvalue.key == "contents"){ + start = mvalue.indices[0][0]-summaryInclude>0?mvalue.indices[0][0]-summaryInclude:0; + end = mvalue.indices[0][1]+summaryInclude