Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Talks widget: Enable separating Upcoming and Past talks into two sections #721

Closed
Bertbk opened this Issue Oct 3, 2018 · 21 comments

Comments

Projects
None yet
3 participants
@Bertbk
Copy link
Contributor

Bertbk commented Oct 3, 2018

I use Academic for a seminar webpage where we store upcoming and past talks. Currently, the talks widget displays every talks, upcoming or not, and is thus not really practical for this kind of usage.

I've added these changes:

  • partials/widgets/talk: "Automatically" separate upcoming and past (automatically = at each building and not, obviously, dynamically)
  • partials/talk_li_simple and partials/talk_li_detailed: Display authors on homepage (if available)

If you guys think this could be relevant for you too, I could send a PR. Proposed changes and options do not change the default behavior of Hugo Academic (= display every talks). I believe this can also be useful for a lab webpage if they hold a regular seminar.

screenshot

More precisly, I added some options to the widgets/talks.md:

  • order: ascending or descending order (usefull for what follows)
  • exclude_past (resp. exclude_upcoming): when true the widget will exclude the past (resp. upcoming) talks. As we are dealing with static website, the dates of talks are compared to the now function and hence to the last building date.

These 2 last options allow me to re-use the talks widget: one for the past (descending order), one for the upcoming (ascending order), without having to move or change the talks/files.md. And if a talk has been given, I just have to rebuild the website to move it to the "past" part without having to move a file (and hence modify its URL).

I also get rid of legacy scratch functions.

PS : in the talk layout, there is a small error: "Event" is shown even if there is "no" event.

@Bertbk Bertbk changed the title Talks widget: "automatic" separate Upcoming and Past talks [suggestion] : Talks widget: "automatic" separate Upcoming and Past talks Oct 16, 2018

@Bertbk

This comment has been minimized.

Copy link
Contributor Author

Bertbk commented Oct 30, 2018

PR proposed #749

@gcushen gcushen changed the title [suggestion] : Talks widget: "automatic" separate Upcoming and Past talks Talks widget: Enable separating Upcoming and Past talks into two sections Nov 9, 2018

@christopherisnow

This comment has been minimized.

Copy link

christopherisnow commented Jan 20, 2019

This looks like a great customization. Can you please provide a workflow for implementation? Not sure exactly what files need to be changed/replaced/created.

@Bertbk

This comment has been minimized.

Copy link
Contributor Author

Bertbk commented Jan 21, 2019

Thanks for your feedback :)

You can have a look at the PR #749 I proposed. You will see there that the main file to change is /layouts/partials/widgets/talks.html.

@christopherisnow

This comment has been minimized.

Copy link

christopherisnow commented Jan 21, 2019

I copied your /layouts/partials/widgets/talks.html to read

{{ $ := .root }}
{{ $page := .page }}
{{ $talks_len := len (where $.Site.RegularPages "Type" "talk") }}

<!-- Talks widget -->
<div class="row">
  <div class="col-12 col-lg-4 section-heading">
    <h1>{{ with $page.Title }}{{ . | markdownify }}{{ end }}</h1>
    {{ with $page.Params.subtitle }}<p>{{ . | markdownify }}</p>{{ end }}
    {{ if gt $talks_len $page.Params.count }}
    <p class="view-all">
      <a href="{{ ($.Site.GetPage "section" "talk").RelPermalink }}">
        {{ i18n "more_talks" | markdownify }}
        <i class="fas fa-angle-double-right"></i>
      </a>
    </p>
    {{ end }}
  </div>
  <div class="col-12 col-lg-8">
    {{ with $page.Content }}<p>{{ . | markdownify }}</p>{{ end }}

    {{ $.Scratch.Set "talks" (where $.Site.RegularPages "Type" "talk") }}

    {{/* Exclude talks shown in Selected Talks widget? */}}
    {{ if $page.Params.exclude_selected }}
    {{ $.Scratch.Set "talks" (where ($.Scratch.Get "talks") ".Params.selected" "!=" true) }}
    {{ end }}

    {{ range first $page.Params.count (sort ($.Scratch.Get "talks") ".Params.time_start" "desc") }}
      {{ if eq $page.Params.list_format 1 }}
        {{ partial "talk_li_detailed" . }}
      {{ else if eq $page.Params.list_format 2 }}
        {{ partial "talk_li_stream" . }}
      {{ else }}
        {{ partial "talk_li_simple" . }}
      {{ end }}
    {{ end }}
  </div>
</div>

and modified these lines of /content/home/talks.md to read

# List format.
#   0 = Simple
#   1 = Detailed
#   2 = Stream
list_format = 2

# Exclude talks that are shown in the Selected Talks widget?
exclude_selected = false

# Exclude past talks (compared to "now") ?
exclude_past = true

 # Exclude upcoming talks (compared to "now") ?
exclude_upcoming = false

 # Order of appearance ("asc" or "desc")
order = "desc"
+++

But nothing happens! Clearly I'm missing something, my skills with this stuff are patchy. Could you please clarify?

@Bertbk

This comment has been minimized.

Copy link
Contributor Author

Bertbk commented Jan 21, 2019

Hello,

Your /layouts/partials/widgets/talks.html seems to be unchanged.

What I advice you to do is:

  1. Do not modify /theme/academics folder! Leave it as "before", so that you get the update from the theme
  2. Build a /layouts/partials/widgets folder (thus outside theme/academic)
  3. Add /layouts/partials/widgets/talks.html by copying/pasting this file

This should makes it work. Keep me in touch!

@christopherisnow

This comment has been minimized.

Copy link

christopherisnow commented Jan 21, 2019

I copied the /layouts/partials/widgets/talks.html file you linked. I get hese errors when building with hugo server:

$ hugo server
Building sites … ERROR 2019/01/21 13:24:02 Failed to add template "partials/widgets/talks.html" in path "/home/christopher/websites/cw_hugo/layouts/partials/widgets/talks.html": template: partials/widgets/talks.html:7: unexpected "=" in operand
ERROR 2019/01/21 13:24:02 partials/widgets/talks.html : template: partials/widgets/talks.html:7: unexpected "=" in operand
ERROR 2019/01/21 13:24:02 Error while rendering "home" in "": template: index.html:1:3: executing "index.html" at <partial "widget_page...>: error calling partial: template: partials/widget_page.html:23:9: executing "partials/widget_page.html" at <partial $widget $par...>: error calling partial: template: "partials/widgets/talks.html" is an incomplete or empty template
Total in 204 ms
Error: Error building site: logged 2 error(s)

Any idea what's up?

@christopherisnow

This comment has been minimized.

Copy link

christopherisnow commented Jan 21, 2019

BTW I found your websites built with Academic https://www.ljll.math.upmc.fr/bthierry/ and https://ljll.math.upmc.fr/infomath/. Would love to copy a few tricks. Is the source code available? Thanks.

@Bertbk

This comment has been minimized.

Copy link
Contributor Author

Bertbk commented Jan 21, 2019

What's your version of Hugo ?

Both website's code are not available, but I'll be happy to help you / send you part of the codes you would like to. For that we can discuss in private (email for example)

@christopherisnow

This comment has been minimized.

Copy link

christopherisnow commented Jan 21, 2019

Hugo Static Site Generator v0.40.3 linux/amd64 BuildDate: 2018-05-09T07:46:33Z

@Bertbk

This comment has been minimized.

Copy link
Contributor Author

Bertbk commented Jan 21, 2019

You should update your hugo version, I guess the error comes from that. Prior to a certain version, it was impossible to reassign a value to a variable, that's why you get an error like this: unexpected "=" in operand

@christopherisnow

This comment has been minimized.

Copy link

christopherisnow commented Jan 21, 2019

Right you are... but even after updating hugo I get new errors:

$ hugo serverTotal in 164 ms
Error: Error building site: failed to render pages: render of "home" failed: execute of template failed: template: index.html:1:3: executing "index.html" at <partial "widget_page...>: error calling partial: execute of template failed: template: partials/widget_page.html:23:9: executing "partials/widget_page.html" at <partial $widget $par...>: error calling partial: "/home/christopher/websites/cw_hugo/layouts/partials/widgets/talks.html:47:11": execute of template failed: template: partials/widgets/talks.html:47:11: executing "partials/widgets/talks.html" at <partial "talk_li_str...>: error calling partial: Partial "talk_li_stream" not found
@Bertbk

This comment has been minimized.

Copy link
Contributor Author

Bertbk commented Jan 21, 2019

Well, that's weird, talk_li_stream is in the academic source code. Maybe try to update the theme ?

sh update_academic.sh 
@christopherisnow

This comment has been minimized.

Copy link

christopherisnow commented Jan 21, 2019

Oy one problem leads to another... what to input after the update script runs? Sorry for my ignorance.

@christopherisnow

This comment has been minimized.

Copy link

christopherisnow commented Jan 21, 2019

First I ran the script and got a list of updates with a : at the end and had to close the terminal window to get out. Then I ran this as suggested at https://sourcethemes.com/academic/docs/update/ and got the same:

$ cd themes/academic
$ git remote rename origin upstream
$ cd themes/academic
$ git fetch upstream
$ git log --pretty=oneline --abbrev-commit --decorate HEAD..upstream/master

Got stuck again before I could run $ git pull upstream. Is there an easy way out or should I just back up my site and reinstall Academic using academic-kickstart?

@Bertbk

This comment has been minimized.

Copy link
Contributor Author

Bertbk commented Jan 21, 2019

Strange... Sometimes my terminal get "stuck" but typing q (for "quit") just do the job. If your website is at the begining, then try indeed a new repo with academic-kickstart...

@christopherisnow

This comment has been minimized.

Copy link

christopherisnow commented Jan 21, 2019

I'm going to start fresh from academic-kickstart. Will get back to you once I copy your previously named files and get my own stuff in order!

@christopherisnow

This comment has been minimized.

Copy link

christopherisnow commented Jan 22, 2019

Apologies for the detour! I reinstalled the newest version of hugo and installed academic-kickstart from scratch. So /layouts/partials/widgets/talks.html returns no errors.

BUT... I still only have a normal Talks widget with no differentiation between Upcoming and Past :) Do I need to create 2 separate Talks widgets manually, or does your talks.html automatically create them? If the former, can you please elaborate?

@Bertbk

This comment has been minimized.

Copy link
Contributor Author

Bertbk commented Jan 22, 2019

You have to create one widget for each "talks display" you want. For example:

  • /content/home/talks_past.md with options exclude_upcoming = true and exclude_past = false
  • /content/home/talks_upcoming.md with option exclude_upcoming = false and exclude_past = true

You can also change the order of display.

@christopherisnow

This comment has been minimized.

Copy link

christopherisnow commented Jan 22, 2019

Hallelujah! Works great, thanks for your help and patience. I had a few questions about how you integrated them into your submenu, but for now let's call it [SOLVED].

Will PM you for the rest :)

@gcushen gcushen added this to the v4.1 milestone Feb 7, 2019

@gcushen gcushen modified the milestones: v4.1, v4.2 Feb 24, 2019

gcushen added a commit that referenced this issue Feb 27, 2019

refactor(talk): rename date options in front matter
date, time_start, time_end renamed to publishDate, date, date_end,
respectively.

BREAKING CHANGES: Rename above 3 options in front matter of all talks.

Also, refactor the 404 page so that it just lists the latest 10 pages
overall. This is a more flexible approach than separately listing the
latest pages for only a few different types of content.

See #721
@gcushen

This comment has been minimized.

Copy link
Owner

gcushen commented Feb 27, 2019

As part of this feature, we will rename the date options in the front matter of all talks in order to gain support for the native Hugo date processing and avoid the previous problems associated with trying to use Hugo with unofficial date params (e.g. time_start, time_end) in YAML front matter (such as RStudio files).

See gohugoio/hugo#3977 (comment)

BREAKING CHANGES

In the front matter of any talks, rename date, time_start, time_end options to publishDate, date, and date_end, respectively.

@Bertbk

This comment has been minimized.

Copy link
Contributor Author

Bertbk commented Feb 28, 2019

Thanks for the merge!

A mistake has however appear during the merge, in the comparison operator in the file layouts/partials/widgets/pages.html:

{{ if $st.Params.content.filters.exclude_past }}
  {{ $query = where $query "Date" "<=" now }} //<-- it should be ">=": we exclude the past so keep the future...
{{ end }}
{{ if $st.Params.content.filters.exclude_future }}
  {{ $query = where $query "Date" ">" now }} //<-- it should be "<"
{{ end }}

Another question is why did you comment the option to sort the talks?

{{/* $sort_by := "Date" */}}
{{/* $query = sort $query $sort_by $items_sort */}}

gcushen added a commit that referenced this issue Feb 28, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.