Skip to content

♻️ refactor: add "target_attribute" macro #515

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tzinm
Copy link
Contributor

@tzinm tzinm commented Apr 14, 2025

Summary

This PR introduces a new macro name target_attribute.html (trying to maintain naming convention). The purpose is to improv code organization in the logic that determines the target="_blank" attribute for external links.

The same logic block is currently repeated in several templates:

  • page.html
  • partials/footer.html
  • partials/cards_pages.html

Additionally, it will also be used in tags/singl.html.

Related issue

It isn't related to any issue but we talked about it in this discussion.

Changes

The new macro contain the following content:

{% macro target_attribute(new_tab=false) %}
 
{%- set blank_target = "" -%}

{%- if new_tab -%}
    {%- set blank_target = "target=_blank" -%}
{%- endif -%}

{{ blank_target }}

{% endmacro target_attribute %}

This macro is imported in base.html:

{% import "macros/target_attribute.html" as macros_target_attribute %}

Usage in the templates:

{%- set blank_target = macros_target_attribute::target_attribute(new_tab=) -%}

Type of change

  • Bug fix (fixes an issue without altering functionality)
  • New feature (adds non-breaking functionality)
  • Breaking change (alters existing functionality)
  • UI/UX improvement (enhances user interface without altering functionality)
  • Refactor (improves code quality without altering functionality)
  • Documentation update
  • Other (please describe below)

Checklist

  • I have verified the accessibility of my changes
  • I have tested all possible scenarios for this change
  • I have updated theme.toml with a sane default for the feature
  • I have updated config.toml in tabi-start
  • I have made corresponding changes to the documentation:
    • Updated config.toml comments
    • Updated theme.toml comments
    • Updated "Mastering tabi" post in English
    • (Optional) Updated "Mastering tabi" post in Spanish
    • (Optional) Updated "Mastering tabi" post in Catalan

@tzinm tzinm requested a review from welpo as a code owner April 14, 2025 16:15
Copy link

netlify bot commented Apr 14, 2025

Deploy Preview for tabi-demo ready!

Name Link
🔨 Latest commit f29db5c
🔍 Latest deploy log https://app.netlify.com/sites/tabi-demo/deploys/67fd34ac8f21a5000862be22
😎 Deploy Preview https://deploy-preview-515--tabi-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

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.

1 participant