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

Transform filetags on a post into a collection for templates #45

Closed
AblatedSprocket opened this issue Apr 2, 2021 · 7 comments
Closed
Labels
good first issue Good for newcomers

Comments

@AblatedSprocket
Copy link
Contributor

Right now when I use the filetags property in a template, it's a string like :emacs:general: Would it be possible to split the tags into a collection you can iterate over?

@clarete
Copy link
Collaborator

clarete commented Apr 10, 2021

Hi @AblatedSprocket thanks for taking the time to post this issue! And this sounds like a great idea, yeah!

Just documenting in case you or anybody else wants to take a stab at it, we need to split the filetags property with split-string.

And I'd fit that in within this function weblorg--parse-org-keyword. More specifically, I'd replace that if with a cond and add a new branch for filetags.

I'd also add a test for that 😄

@clarete clarete added the good first issue Good for newcomers label Apr 10, 2021
@AblatedSprocket
Copy link
Contributor Author

I've wanted to get involved in the project, I'll try to find some bandwidth to work on this. Thank you for explaining what needs to be done.

@AblatedSprocket
Copy link
Contributor Author

Making the change as you suggested does create a collection of tags accessible to the templates. It also has the unhappy side-effect of forcing the filenames of the generated HTML files to be the full path of the Org file, but hyphenated. So path/to/my/post.org generates a file named path-to-my-post-org.html. I'm trying to understand why this happens, but my elisp is not great. In case anyone is curious, the modified function is below:

(defun weblorg--parse-org-keyword (keyword)
  "Parse a single Org-Mode document KEYWORD.

If it's a date field, it will return a timestamp tuple instead of
the value string.  The user will have to use the `strftime`
template filter to display a nicely formatted string.

If it's a filetag field, it will return a collection of strings.
The user will have to iterate over the collection to get all keywords."
  (let ((key (downcase (org-element-property :key keyword)))
        (value (org-element-property :value keyword)))
    (cons
     key
     (cond ((string= key "date")
            ;; use the deprecated signature of `encode-time' to keep
            ;; compatibility to Emacs 26x.
            (apply #'encode-time (org-parse-time-string value)))
           ((string= key "filetags")
            (split-string value ":" t))))))

@clarete
Copy link
Collaborator

clarete commented Apr 16, 2021

Hi @AblatedSprocket, thank you so much for writing this up. This looks pretty good as far as I can tell. I would probably think of adding a test to the t/test-weblorg.el file for parsing the date of an actual Org-Mode file, but I think the code change is mostly there 😄

On the file name that is being generated from weblorg, I can't see anything in your change that could be causing that. We have an issue tracking something slightly different (#27). If you don't figure that out, I'd still suggest to get the PR up, so then I can test your code in my environment!

Pretty exciting stuff!! Thank you for taking the time 🙇🏾

@clarete
Copy link
Collaborator

clarete commented Apr 25, 2021

With the PR #50 merged, @AblatedSprocket do you think there's anything else we would need to do to cover this feature?

@AblatedSprocket
Copy link
Contributor Author

Sorry, I don't know how I missed your comment. This feature's got everything I need out of it. :)

@clarete
Copy link
Collaborator

clarete commented May 7, 2021

No worries! Thanks for confirming!! 😄

@clarete clarete closed this as completed May 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants