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

Scratch and Output Formats #3592

Open
sascha53 opened this issue Jun 14, 2017 · 2 comments
Open

Scratch and Output Formats #3592

sascha53 opened this issue Jun 14, 2017 · 2 comments
Milestone

Comments

@sascha53
Copy link

sascha53 commented Jun 14, 2017

I use partials for inlining svg defs, for example:

{{- $icon_id := "line-chart" -}}
{{- $icon_name := add "icon-" $icon_id -}}
{{- if not (.Scratch.Get $icon_name) -}}{{- .Scratch.Set $icon_name true -}}<svg class="clip" xmlns="http:https://www.w3.org/2000/svg" width="0" height="0"><defs><svg id="{{ $icon_id }}" xmlns="http:https://www.w3.org/2000/svg" fill="currentcolor" viewBox="0 0 1792 1792"><path d="M1920 1536v128h-2048v-1536h128v1408h1920zm-128-1248v435q0 21-19.5 29.5t-35.5-7.5l-121-121-633 633q-10 10-23 10t-23-10l-233-233-416 416-192-192 585-585q10-10 23-10t23 10l233 233 464-464-121-121q-16-16-7.5-35.5t29.5-19.5h435q14 0 23 9t9 23z"/></svg></defs></svg>{{- end }}

The goal is to inline a svg defs just once per page, as i reference them with xlink:href. This is what the if statement is made for and that worked well before activating another output format like AMP, which is also using this icon partial in its template.

It seems that the vars defined in Scratch are "reseted" per page, but if you use multiple Output Formats, they are shared and not reseted. The undesired behaviour in my case: Either on the HTML or AMP version of the same page, which is rendered after the other (which is random) the var is already set to true and the svg def isn't rendered.

This also doesn't work:

{{- $id := "facebook" -}}
{{- $name := add "icon-" $id -}}
{{- if lt (.Scratch.Get $name) (len .OutputFormats) -}}
{{- .Scratch.Set $name (add (int (.Scratch.Get $name)) 1) -}}
<svg class="clip" xmlns="http:https://www.w3.org/2000/svg" width="0" height="0">
<defs>
<svg viewBox="0 0 1792 1792" xmlns="http:https://www.w3.org/2000/svg" id="{{ $id }}" fill="currentcolor"><path d="M1343 12v264h-157q-86 0-116 36t-30 108v189h293l-39 296h-254v759h-306v-759h-255v-296h255v-218q0-186 104-288.5t277-102.5q147 0 228 12z"/></svg>
</defs>
</svg>
{{- end }}

The solution would be either a proper reset of the Scratch vars for every Output Format. Or a page variable that tells me which output format is currently rendered (or extension) and that i can use in an if statement. Or maybe something else.

@bep bep modified the milestones: v0.23, v0.24, v0.25 Jun 14, 2017
@bep bep modified the milestones: v0.25, v0.26 Jul 5, 2017
@bep bep modified the milestones: v0.26, v0.27 Aug 6, 2017
@bep bep modified the milestones: v0.27, v0.28 Sep 7, 2017
@bep bep modified the milestones: v0.28, v0.29, v0.30 Sep 21, 2017
@bep bep modified the milestones: v0.30, v0.31 Oct 13, 2017
@bep bep modified the milestones: v0.31, v0.32 Oct 30, 2017
@bep bep modified the milestones: v0.114.0, v0.115.0 Jun 13, 2023
@bep bep modified the milestones: v0.115.0, v0.116.0 Jun 30, 2023
@bep bep modified the milestones: v0.116.0, v0.117.0 Aug 1, 2023
@bep bep modified the milestones: v0.117.0, v0.118.0 Aug 30, 2023
@bep bep modified the milestones: v0.118.0, v0.119.0 Sep 15, 2023
@bep bep modified the milestones: v0.119.0, v0.120.0 Oct 4, 2023
@bep bep modified the milestones: v0.120.0, v0.121.0 Oct 31, 2023
@bep bep modified the milestones: v0.121.0, v0.122.0 Dec 6, 2023
@bep bep modified the milestones: v0.122.0, v0.123.0, v0.124.0 Jan 27, 2024
@bep bep modified the milestones: v0.124.0, v0.125.0 Mar 4, 2024
@bep bep modified the milestones: v0.125.0, v0.126.0 Apr 23, 2024
@bep bep modified the milestones: v0.126.0, v0.127.0 May 15, 2024
@bep bep modified the milestones: v0.127.0, v0.128.0 Jun 8, 2024
@bep bep modified the milestones: v0.128.0, v0.129.0 Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants