From 3d4884a9f045a5895746e5bca694ec230574fcf2 Mon Sep 17 00:00:00 2001 From: George Cushen Date: Mon, 16 Oct 2017 02:05:39 +0100 Subject: [PATCH] publications: Add citation feature + improvements (#302 #310 #205 #286) * Add citation feature (#302) * Remove detail button since all pub. titles are now linked (#310) * Optimize order of pub. buttons and add more button options (#205) * Use noopener for external URLs that open in new tabs (#286) --- archetypes/publication.md | 3 ++ .../content/publication/clothing-search.md | 3 ++ .../files/citations/clothing-search.bib | 8 +++ i18n/en.yaml | 19 ++++++- layouts/partials/css/academic.css | 20 ++++++++ layouts/partials/footer_container.html | 24 +++++++++ layouts/partials/publication_links.html | 51 +++++++++++++------ static/js/hugo-academic.js | 34 +++++++++++++ 8 files changed, 144 insertions(+), 18 deletions(-) create mode 100644 exampleSite/static/files/citations/clothing-search.bib diff --git a/archetypes/publication.md b/archetypes/publication.md index 2a480e8b..f7466755 100644 --- a/archetypes/publication.md +++ b/archetypes/publication.md @@ -39,11 +39,14 @@ selected = false # Links (optional) url_pdf = "" +url_preprint = "" url_code = "" url_dataset = "" url_project = "" url_slides = "" url_video = "" +url_poster = "" +url_source = "" # Featured image # Place your image in the `static/img/` folder and reference its filename below, e.g. `image = "example.jpg"`. diff --git a/exampleSite/content/publication/clothing-search.md b/exampleSite/content/publication/clothing-search.md index df3dba32..e32660c2 100644 --- a/exampleSite/content/publication/clothing-search.md +++ b/exampleSite/content/publication/clothing-search.md @@ -16,6 +16,9 @@ url_pdf = "http://eprints.soton.ac.uk/352095/1/Cushen-IMV2013.pdf" url_project = "project/deep-learning/" url_slides = "#" url_video = "#" +url_poster = "#" +url_preprint = "http://eprints.soton.ac.uk/352095/1/Cushen-IMV2013.pdf" +url_source = "#" [[url_custom]] name = "Custom Link" diff --git a/exampleSite/static/files/citations/clothing-search.bib b/exampleSite/static/files/citations/clothing-search.bib new file mode 100644 index 00000000..fe3ed0f3 --- /dev/null +++ b/exampleSite/static/files/citations/clothing-search.bib @@ -0,0 +1,8 @@ +@inproceedings{cushen2013mobile, + title={Mobile visual clothing search}, + author={Cushen, George A and Nixon, Mark S}, + booktitle={IEEE International Conference on Multimedia and Expo Workshops}, + pages={1--6}, + year={2013}, + organization={IEEE} +} diff --git a/i18n/en.yaml b/i18n/en.yaml index 4d861a32..44aa95be 100644 --- a/i18n/en.yaml +++ b/i18n/en.yaml @@ -16,12 +16,15 @@ # Buttons -- id: btn_details - translation: Details +- id: btn_preprint + translation: Preprint - id: btn_pdf translation: PDF +- id: btn_cite + translation: Cite + - id: btn_slides translation: Slides @@ -37,6 +40,18 @@ - id: btn_project translation: Project +- id: btn_poster + translation: Poster + +- id: btn_source + translation: Source Document + +- id: btn_copy + translation: Copy + +- id: btn_download + translation: Download + # About widget - id: interests diff --git a/layouts/partials/css/academic.css b/layouts/partials/css/academic.css index 71517230..ff6c9eec 100644 --- a/layouts/partials/css/academic.css +++ b/layouts/partials/css/academic.css @@ -201,6 +201,26 @@ small, font-size: .75em; } +/************************************************* + * Modals. + **************************************************/ + +.modal-header .close { + font-size: 40px; /* Bigger cross. */ + height: 30px; /* Remove icon's vertical spacing. */ + overflow-y: hidden; + position: relative; + top: -5px; +} + +.modal-content pre { + margin: 0; +} + +#modal-error { + color: red; +} + /************************************************* * Home Sections **************************************************/ diff --git a/layouts/partials/footer_container.html b/layouts/partials/footer_container.html index 0072f22f..a3a51416 100644 --- a/layouts/partials/footer_container.html +++ b/layouts/partials/footer_container.html @@ -19,3 +19,27 @@

+ + + diff --git a/layouts/partials/publication_links.html b/layouts/partials/publication_links.html index e871dab8..e3d40214 100644 --- a/layouts/partials/publication_links.html +++ b/layouts/partials/publication_links.html @@ -1,33 +1,32 @@ {{ $is_list := .is_list }} {{ $ := .content }} -{{ if $is_list }} - - {{ i18n "btn_details" }} +{{ with $.Params.url_preprint }} + + {{ i18n "btn_preprint" }} {{ end }} {{ with $.Params.url_pdf }} - + {{ i18n "btn_pdf" }} {{ end }} -{{ with $.Params.url_slides }} - - {{ i18n "btn_slides" }} - -{{ end }} -{{ with $.Params.url_video }} - - {{ i18n "btn_video" }} - +{{/* TODO: After Hugo v0.30 released, use fileExists function here. */}} +{{ $directory := "static/files/citations/" }} +{{ $filename := printf "%s.bib" $.File.TranslationBaseName }} +{{ if (where (readDir $directory) "Name" $filename) }} + {{ end }} {{ with $.Params.url_code }} - + {{ i18n "btn_code" }} {{ end }} {{ with $.Params.url_dataset }} - + {{ i18n "btn_dataset" }} {{ end }} @@ -36,8 +35,28 @@ {{ i18n "btn_project" }} {{ end }} +{{ with $.Params.url_poster }} + + {{ i18n "btn_poster" }} + +{{ end }} +{{ with $.Params.url_slides }} + + {{ i18n "btn_slides" }} + +{{ end }} +{{ with $.Params.url_video }} + + {{ i18n "btn_video" }} + +{{ end }} +{{ with $.Params.url_source }} + + {{ i18n "btn_source" }} + +{{ end }} {{ range $.Params.url_custom }} - + {{ .name }} {{ end }} diff --git a/static/js/hugo-academic.js b/static/js/hugo-academic.js index d83aff09..b0daa065 100644 --- a/static/js/hugo-academic.js +++ b/static/js/hugo-academic.js @@ -269,6 +269,40 @@ // window.addEventListener('hashchange', filter_publications, false); } + // Load citation modal on 'Cite' click. + $('.js-cite-modal').click(function(e) { + e.preventDefault(); + let filename = $(this).attr('data-filename'); + let modal = $('#modal'); + modal.find('.modal-body').load( filename , function( response, status, xhr ) { + if ( status == 'error' ) { + let msg = "Error: "; + $('#modal-error').html( msg + xhr.status + " " + xhr.statusText ); + } else { + $('.js-download-cite').attr('href', filename); + } + }); + modal.modal('show'); + }); + + // Copy citation text on 'Copy' click. + $('.js-copy-cite').click(function(e) { + e.preventDefault(); + // Get selection. + let range = document.createRange(); + let code_node = document.querySelector('#modal .modal-body'); + range.selectNode(code_node); + window.getSelection().addRange(range); + try { + // Execute the copy command. + document.execCommand('copy'); + } catch(e) { + console.log('Error: citation copy failed.'); + } + // Remove selection. + window.getSelection().removeRange(range); + }); + // Initialise Google Maps if necessary. initMap(); });