Make links detect target automatically and replace false with null for no attribute

New version of Harp would render attribute=false as attribute="false",
while attribute=null renders element without attribute.
This commit is contained in:
Ines Montani 2016-12-24 12:24:04 +01:00
parent b893126c12
commit f6f6e028ea
5 changed files with 14 additions and 12 deletions

View File

@ -11,7 +11,7 @@ footer.o-footer.u-text.u-border-dotted
each url, item in group each url, item in group
li li
+a(url)(target=url.includes("http") ? "_blank" : false)=item +a(url)=item
if SECTION != "docs" if SECTION != "docs"
+grid-col("quarter") +grid-col("quarter")

View File

@ -20,7 +20,8 @@ mixin h(level, id)
info: https://mathiasbynens.github.io/rel-noopener/ info: https://mathiasbynens.github.io/rel-noopener/
mixin a(url, trusted) mixin a(url, trusted)
a(href=url target="_blank" rel=!trusted ? "noopener nofollow" : false)&attributes(attributes) - external = url.includes("http")
a(href=url target=external ? "_blank" : null rel=external && !trusted ? "noopener nofollow" : null)&attributes(attributes)
block block
@ -74,7 +75,8 @@ mixin aside-code(label, language)
see assets/css/_components/_buttons.sass see assets/css/_components/_buttons.sass
mixin button(url, trusted, ...style) mixin button(url, trusted, ...style)
a.c-button.u-text-label(href=url class=prefixArgs(style, "c-button") role="button" target="_blank" rel=!trusted ? "noopener nofollow" : false)&attributes(attributes) - external = url.includes("http")
a.c-button.u-text-label(href=url class=prefixArgs(style, "c-button") role="button" target=external ? "_blank" : null rel=external && !trusted ? "noopener nofollow" : null)&attributes(attributes)
block block
@ -148,7 +150,7 @@ mixin tag()
mixin list(type, start) mixin list(type, start)
if type if type
ol.c-list.o-block.u-text(class="c-list--#{type}" style=(start === 0 || start) ? "counter-reset: li #{(start - 1)}" : false)&attributes(attributes) ol.c-list.o-block.u-text(class="c-list--#{type}" style=(start === 0 || start) ? "counter-reset: li #{(start - 1)}" : null)&attributes(attributes)
block block
else else

View File

@ -2,7 +2,7 @@
include _mixins include _mixins
nav.c-nav.u-text.js-nav(class=landing ? "c-nav--theme" : false) nav.c-nav.u-text.js-nav(class=landing ? "c-nav--theme" : null)
a(href='/') #[+logo] a(href='/') #[+logo]
if SUBSECTION != "index" if SUBSECTION != "index"
@ -11,7 +11,7 @@ nav.c-nav.u-text.js-nav(class=landing ? "c-nav--theme" : false)
ul.c-nav__menu ul.c-nav__menu
each url, item in NAVIGATION each url, item in NAVIGATION
li.c-nav__menu__item li.c-nav__menu__item
a(href=url target=url.includes("http") ? "_blank" : false)=item +a(url)=item
li.c-nav__menu__item li.c-nav__menu__item
+a(gh("spaCy"))(aria-label="GitHub").u-hidden-xs #[+icon("github", 20)] +a(gh("spaCy"))(aria-label="GitHub").u-hidden-xs #[+icon("github", 20)]

View File

@ -9,5 +9,5 @@ menu.c-sidebar.js-sidebar.u-text
li.u-text-label.u-color-subtle=menu li.u-text-label.u-color-subtle=menu
each url, item in items each url, item in items
li(class=(CURRENT == url || (CURRENT == "index" && url == "./")) ? "is-active" : false) li(class=(CURRENT == url || (CURRENT == "index" && url == "./")) ? "is-active" : null)
+a(url)(target=url.includes("http") ? "_blank" : false)=item +a(url)=item

View File

@ -22,7 +22,7 @@ include _includes/_mixins
| process entire web dumps, spaCy is the library you want to | process entire web dumps, spaCy is the library you want to
| be using. | be using.
+button("/docs/api", true, "primary")(target="_self") +button("/docs/api", true, "primary")
| Facts & figures | Facts & figures
+grid-col("third").o-card +grid-col("third").o-card
@ -35,7 +35,7 @@ include _includes/_mixins
| think of spaCy as the Ruby on Rails of Natural Language | think of spaCy as the Ruby on Rails of Natural Language
| Processing. | Processing.
+button("/docs/usage", true, "primary")(target="_self") +button("/docs/usage", true, "primary")
| Get started | Get started
+grid-col("third").o-card +grid-col("third").o-card
@ -51,7 +51,7 @@ include _includes/_mixins
| connect the statistical models trained by these libraries | connect the statistical models trained by these libraries
| to the rest of your application. | to the rest of your application.
+button("/docs/usage/deep-learning", true, "primary")(target="_self") +button("/docs/usage/deep-learning", true, "primary")
| Read more | Read more
.o-inline-list.o-block.u-border-bottom.u-text-small.u-text-center.u-padding-small .o-inline-list.o-block.u-border-bottom.u-text-small.u-text-center.u-padding-small
@ -105,7 +105,7 @@ include _includes/_mixins
+item Robust, rigorously evaluated accuracy +item Robust, rigorously evaluated accuracy
.o-inline-list .o-inline-list
+button("/docs/usage/lightning-tour", true, "secondary")(target="_self") +button("/docs/usage/lightning-tour", true, "secondary")
| See examples | See examples
.o-block.u-text-center.u-padding .o-block.u-text-center.u-padding