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

creating a Date object from fd_mtime? #700

Closed
tomohiro-soejima opened this issue Nov 5, 2020 · 6 comments
Closed

creating a Date object from fd_mtime? #700

tomohiro-soejima opened this issue Nov 5, 2020 · 6 comments
Labels

Comments

@tomohiro-soejima
Copy link
Contributor

Hi,

I would like to create a Date object from fd_mtime to be used in e.g. indicating last modified time on my blog post. However, adding this to the top of my markdown file does not work

@def last_modified=Date(fd_mtime)

becaue fd_mtime is not defined in this scope. What is the best way to define such last_modified.

In case there are other ways to handle this, here is an excerpt of the header that I want to make work.

{{ispage /blog/julia/*}}
<div class="container blog-title">
	{{isdef title}}<h1>{{fill title}}</h1>{{end}}
  <h3>
  {{isdef published}} <span style="font-weight: lighter;"> posted: {{fill published}} 
  
  last modified: {{isdef last_modified}}{{fill last_modified}}{{end}}
  </span>
	|
	{{end}}
	{{isdef author}} <span style="font-weight: bold;">{{fill author}}</span> {{end}}
  <!-- assumption that only one of the two is defined -->
  {{isdef authors}} <span style="font-weight: bold;">{{fill authors}} </span> {{end}}
  </h3>
</div>
<br>
{{end}}
@tlienart
Copy link
Owner

tlienart commented Nov 5, 2020

you should access fd_mtime via locvar:

@def last_modified=Date(locvar(:fd_mtime))

you can test this quickly in a Julia session (this is what I did before answering):

s = """
    @def last_modified=Date(locvar(:fd_mtime))
    {{last_modified}}
    """ |> fd2html

this will show 0001-01-01 because it's not executed in a file but you get the idea.

@tlienart
Copy link
Owner

tlienart commented Nov 5, 2020

By the way why did you not just do {{fd_mtime}} in your header? did you want to re-format the date? in any case let me know if this works for you and if not maybe give me more information about what you're trying to get as final result?

Note {{ xxx }} is short for {{fill xxx}} in cases where xxx is not ambiguous.

@tomohiro-soejima
Copy link
Contributor Author

thank you for your quick response!

I tried your code snippet, but it printed 0001-01-01. Looks like fd_mtime is not correctly formatted for Date to parse. Is there a way around this?

I wanted to convert fd_mtime to Date, since published is a Date object, and I'd like to use the same format for published and last_modified.

The {{isdef published}} is closed two lines after </span>. Sorry for the bad indentation!

@tomohiro-soejima
Copy link
Contributor Author

this is what I want the end result to look like (with the correct last-modified date):

image

@tlienart
Copy link
Owner

tlienart commented Nov 5, 2020

Ah right you want fd_mtime_raw: consider the following, the first one is what you want, the second one is formatted. Sorry for my previous response.

Last modified: {{fd_mtime_raw}} or {{fd_mtime}}

(I should add that one in the docs...)

@tomohiro-soejima
Copy link
Contributor Author

That worked like a charm! Thanks.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants