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

Make templates return results properly instead of abusing .Scratch #153

Merged
merged 10 commits into from
May 17, 2020
Merged

Make templates return results properly instead of abusing .Scratch #153

merged 10 commits into from
May 17, 2020

Conversation

palant
Copy link
Collaborator

@palant palant commented May 15, 2020

The initial commit fixes #137. I also could fail to notice that hrefTargetBlank processing in markdownify.html seems very inefficient - let me know if I missed something that the original code was doing better.

I must say that I didn't test the changes to content.html fully - it's way too many branches and settings. But the changes are pretty straightforward.

I want to add more commits to this pull request, there are other templates following the same pattern.

@palant
Copy link
Collaborator Author

palant commented May 15, 2020

Somewhat more extensive changes to auto-detect-images.html and images.html - these implemented pretty much the same logic concerning the image host. Now this logic is applied to the entire list of images, regardless of where the images came from. Also, auto-detect-images.html template now only executes as a fallback instead of executing even when it isn't needed.

@reuixiy
Copy link
Owner

reuixiy commented May 16, 2020

I also could fail to notice that hrefTargetBlank processing in markdownify.html seems very inefficient

Yeah... That was awkward, I'm not sure why I wrote that way now. 🤣

I must say that I didn't test the changes to content.html fully

I have tested it and everything works fine.

Somewhat more extensive changes to auto-detect-images.html and images.html

Love this refactoring!

@palant
Copy link
Collaborator Author

palant commented May 16, 2020

Side-notes: title.html will only pass page titles through plainify, not other titles - looks wrong. Also, images.html should probably recognize image names from the page bundle, something for another pull request.

@palant
Copy link
Collaborator Author

palant commented May 17, 2020

The changes to relative-url.html are more extensive again. The ./ prefix is unnecessary for a relative URL, so the template could be simplified. I also got rid of an unnecessary safeJS call in service-worker.html - I could verify that the code was emitted correctly here but I cannot test the functionality.

@palant
Copy link
Collaborator Author

palant commented May 17, 2020

It seems that I am done here. The change to utils/tree-sections.html is completely untested however because I have no idea under which circumstances this template is being used.

@reuixiy
Copy link
Owner

reuixiy commented May 17, 2020

categoryBy = "sections"
layouts/section/categories.html
layouts/partials/pages/tree-sections.html
↳ Generated something like this page but for sections.

In other words, I want to implement a categories page that displays like the output of tree command. So I created utils/tree-sections.html for this, although I don't know if there is a better way.

@reuixiy
Copy link
Owner

reuixiy commented May 17, 2020

@palant Everything works well except the last commit, which returns an empty map[].

Also, there are more .Scratchs we can remove, something for another pull request again. (To be honest, I didn't know the = operator until I found it in your commits.)

BTW, do you mind if I invite you as a collaborator of this repository? 😊

@palant
Copy link
Collaborator Author

palant commented May 17, 2020

Ok, I rolled back that last change. It's probably that one scenario where one actually has to use .Scratch - blocks cannot access external variables, and they cannot return a result either.

↳ Generated something like this page but for sections.

Yes, I got this in theory but couldn't make that page generated.

BTW, do you mind if I invite you as a collaborator of this repository? 😊

I guess that's ok but I cannot promise regular contributions.

@reuixiy
Copy link
Owner

reuixiy commented May 17, 2020

I guess that's ok but I cannot promise regular contributions.

No problem. I have invited you, and after you accept it, you should be able to merge this PR. 😊

Additionally, the commit messages, please follow the Conventional Commits, as MemE's changelog is based on it.

Thanks again :)

@palant
Copy link
Collaborator Author

palant commented May 17, 2020

So the title of this commit should be "BREAKING CHANGE: Make templates return results properly instead of abusing .Scratch (#153)", right?

@reuixiy
Copy link
Owner

reuixiy commented May 17, 2020

Hmmm, refactor sounds better,

refactor: Make templates return results properly (#153)

...instead of abusing .Scratch

Fixes #137

[...]

@palant
Copy link
Collaborator Author

palant commented May 17, 2020

Well, it is a breaking change for anybody overriding templates 😄

@reuixiy
Copy link
Owner

reuixiy commented May 17, 2020

Then maybe we can add it in the footer, I guess.

refactor: Make templates return results properly (#153)

...instead of abusing .Scratch

Fixes #137

[...]

BREAKING CHANGE: <description>

@palant palant merged commit 418f72d into reuixiy:master May 17, 2020
ulmefors pushed a commit to ulmefors/hugo-theme-meme that referenced this pull request Nov 22, 2020
...instead of abusing .Scratch

Fixes reuixiy#137

* Make markdownify.html and content.html return results properly

* Make author.html return results properly

* Make auto-detect-images.html and images.html return results properly

* Make date.html return results properly

* Make data-attributes.html return result properly

* Make title.html return results properly

* Make toc.html return results properly

* Make relative-url.html return results properly

* Make tree-sections.html return results properly (untested)

* Rolled back change to tree-sections.html, doesn't work

BREAKING CHANGE: Various templates under `utils/partials/` will return results directly rather than via `.Scratch` now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

markdownify.html should not return result via scratch
2 participants