From ae3a75777794a0806d44b3b68c4e4e19aae0fa62 Mon Sep 17 00:00:00 2001 From: George Cushen Date: Thu, 12 Jan 2017 06:41:13 +0000 Subject: [PATCH] Add publication filter #26 --- archetypes/publication.md | 38 ++++++++++-- exampleSite/config.toml | 21 +++++++ .../content/publication/clothing-search.md | 1 + .../publication/person-re-identification.md | 1 + i18n/en.yaml | 11 ++++ layouts/publication/single.html | 20 +++++++ layouts/section/publication.html | 43 +++++++------ static/css/hugo-academic.css | 5 ++ static/js/hugo-academic.js | 60 +++++++++++++++++-- 9 files changed, 173 insertions(+), 27 deletions(-) diff --git a/archetypes/publication.md b/archetypes/publication.md index f6692abc..a0ba4ceb 100644 --- a/archetypes/publication.md +++ b/archetypes/publication.md @@ -1,17 +1,45 @@ +++ -abstract = "" -abstract_short = "" + +# Authors. Comma separated list, e.g. `["Bob Smith", "David Jones"]`. authors = [""] -image = "" -image_preview = "" -math = false + +# Publication type. +# Legend: +# 0 = Uncategorized +# 1 = Conference proceedings +# 2 = Journal +# 3 = Work in progress +# 4 = Technical report +# 5 = Book +# 6 = Book chapter +publication_types = ["0"] + +# Publication name and optional abbreviated version. publication = "" publication_short = "" + +# Abstract and optional shortened version. +abstract = "" +abstract_short = "" + +# Does this page contain LaTeX math? (true/false) +math = false + +# Featured image (optional) +image = "" + +# Featured image thumbnail (optional) +image_preview = "" + +# Is this a selected publication? (true/false) selected = false + +# Links (optional) url_pdf = "" url_code = "" url_dataset = "" url_project = "" url_slides = "" url_video = "" + +++ diff --git a/exampleSite/config.toml b/exampleSite/config.toml index 27043681..3ea65379 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -49,6 +49,21 @@ defaultContentLanguageInSubdir = false custom_css = [] custom_js = [] + # Publication types. + # Used to categorize publications. + # The index of the publication type in the list is used as its unique numerical identifier. + # The numeric ID is used in a publication's frontmatter to categorize it. + # The language can be edited below. + # For multi-lingual sites, copy this block to each language section at the end of this file. + publication_types = [ + 'Uncategorized', # 0 + 'Conference proceedings', # 1 + 'Journal', # 2 + 'Work in progress', # 3 + 'Technical report', # 4 + 'Book', # 5 + 'Book chapter' # 6 + ] # Social/Academic Networking # @@ -124,6 +139,12 @@ defaultContentLanguageInSubdir = false url = "#contact" weight = 6 +# Taxonomies. +[taxonomies] + tag = "tags" + category = "categories" + publication_type = "publication_types" + # Languages # Create a [languages.X] block for each language you want, where X is the language ID. diff --git a/exampleSite/content/publication/clothing-search.md b/exampleSite/content/publication/clothing-search.md index d564c327..d2806b7f 100644 --- a/exampleSite/content/publication/clothing-search.md +++ b/exampleSite/content/publication/clothing-search.md @@ -6,6 +6,7 @@ date = "2013-07-01" image = "" image_preview = "" math = true +publication_types = ["1"] publication = "In *International Conference on Multimedia and Expo Workshops (ICMEW)*, IEEE." publication_short = "In *ICMEW*" selected = true diff --git a/exampleSite/content/publication/person-re-identification.md b/exampleSite/content/publication/person-re-identification.md index 06fd7a66..d0d4be79 100644 --- a/exampleSite/content/publication/person-re-identification.md +++ b/exampleSite/content/publication/person-re-identification.md @@ -6,6 +6,7 @@ date = "2015-09-01" image = "" image_preview = "" math = true +publication_types = ["2"] publication = "In *Signal Image Technology & Internet Systems (SITIS)*, IEEE." publication_short = "" selected = false diff --git a/i18n/en.yaml b/i18n/en.yaml index 6c3f4411..a9624e2c 100644 --- a/i18n/en.yaml +++ b/i18n/en.yaml @@ -60,6 +60,9 @@ - id: publication translation: Publication +- id: publication_type + translation: Type + - id: date translation: Date @@ -72,6 +75,14 @@ - id: location translation: Location +# Filtering + +- id: filter_by_type + translation: Filter by type + +- id: filter_all + translation: All + # Project details - id: open_project_site diff --git a/layouts/publication/single.html b/layouts/publication/single.html index 11e88876..57fc3744 100644 --- a/layouts/publication/single.html +++ b/layouts/publication/single.html @@ -22,6 +22,26 @@

{{ i18n "abstract" }}

{{ .Params.abstract }}

+ {{ if (.Params.publication_types) and (ne (index .Params.publication_types 0) "0") }} +
+
+
+
+
{{ i18n "publication_type" }}
+
+ {{ range $index, $pubtype := .Params.publication_types }} + + {{ index $.Site.Params.publication_types (int .) }} + + {{ end }} +
+
+
+
+
+
+ {{ end }} +
diff --git a/layouts/section/publication.html b/layouts/section/publication.html index 1a66a8af..ccdd9e2a 100644 --- a/layouts/section/publication.html +++ b/layouts/section/publication.html @@ -5,31 +5,38 @@

{{ i18n "publications" }}

- {{ range .Data.Pages.GroupByDate "2006" }} -
-
-

{{ .Key }}

-
-
-
    +

    + {{ i18n "filter_by_type" }}: + +

    - {{ range .Pages.ByDate.Reverse }} -
  • - - {{ .Title }} -

    {{ partial "publication_links" (dict "content" . "is_list" 1) }}

    -
  • - {{ end }} +
    + {{ range .Pages.ByDate.Reverse }} -
+ {{ if .Params.publication_types }} + {{ $.Scratch.Set "pubtype" (index .Params.publication_types 0) }} + {{ else }} + {{ $.Scratch.Set "pubtype" 0 }} + {{ end }} + +
+ {{ .Title }} +

{{ partial "publication_links" (dict "content" . "is_list" 1) }}

+ + {{ end }}
- {{ end }}
-
{{ partial "footer_container.html" . }} {{ partial "footer.html" . }} diff --git a/static/css/hugo-academic.css b/static/css/hugo-academic.css index 55411a2c..04890072 100644 --- a/static/css/hugo-academic.css +++ b/static/css/hugo-academic.css @@ -491,6 +491,11 @@ article { padding-top: 10px; } +#container-publications { + display: block; + position: relative; + overflow: hidden; +} /************************************************* * Talks diff --git a/static/js/hugo-academic.js b/static/js/hugo-academic.js index 5881870d..2c580278 100644 --- a/static/js/hugo-academic.js +++ b/static/js/hugo-academic.js @@ -93,10 +93,10 @@ * Filter projects. * --------------------------------------------------------------------------- */ - var $container = $('#container-projects'); - $container.imagesLoaded(function () { + var $grid_projects = $('#container-projects'); + $grid_projects.imagesLoaded(function () { // Initialize Isotope after all images have loaded. - $container.isotope({ + $grid_projects.isotope({ itemSelector: '.isotope-item', layoutMode: 'masonry' }); @@ -104,18 +104,70 @@ // Filter items when filter link is clicked. $('#filters a').click(function () { var selector = $(this).attr('data-filter'); - $container.isotope({filter: selector}); + $grid_projects.isotope({filter: selector}); $(this).removeClass('active').addClass('active').siblings().removeClass('active all'); return false; }); }); + /* --------------------------------------------------------------------------- + * Filter publications. + * --------------------------------------------------------------------------- */ + + var $grid_pubs = $('#container-publications'); + $grid_pubs.isotope({ + itemSelector: '.isotope-item', + percentPosition: true, + masonry: { + // Use Bootstrap compatible grid layout. + columnWidth: '.grid-sizer' + } + }); + + // Bind publication filter on dropdown change. + $('.pub-filters-select').on( 'change', function() { + // Get filter value from option value. + var filterValue = this.value; + // Apply filter to Isotope. + $grid_pubs.isotope({ filter: filterValue }); + + // Set hash URL to current filter. + var url = $(this).val(); + if (url.substr(0, 9) == '.pubtype-') { + window.location.hash = url.substr(9); + } else { + window.location.hash = ''; + } + }); + + // Filter publications according to hash in URL. + function filter_publications() { + var urlHash = window.location.hash.replace('#',''); + var filterValue = '*'; + + // Check if hash is numeric. + if (urlHash != '' && !isNaN(urlHash)) { + filterValue = '.pubtype-' + urlHash; + } + + $('.pub-filters-select').val(filterValue); + $grid_pubs.isotope({ filter: filterValue }); + } + /* --------------------------------------------------------------------------- * On window load. * --------------------------------------------------------------------------- */ $(window).load(function(){ + // When accessing publication index, enable filtering. + if ($('.pub-filters-select')) { + filter_publications(); + + // Useful for changing hash manually (e.g. in development): + // window.addEventListener('hashchange', filter_publications, false); + } + // Enable smooth scrolling with mouse wheel smoothScroll(1.3, 220);