Skip to content

Commit

Permalink
fixes #102 unnecessary directory redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
gibatronic committed Oct 16, 2021
1 parent f99ccb2 commit 0568104
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
14 changes: 7 additions & 7 deletions client/scripts/asset-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,23 @@ export default class AssetLink extends CustomElement(HTMLAnchorElement) {
highlight(highlightedGraphemes) {
const regExp = new RegExp(`^(${highlightedGraphemes})`, 'iu')

this.highlighted = highlightedGraphemes !== '' && regExp.test(this.url)
this.highlighted = highlightedGraphemes !== '' && regExp.test(this.name)

if (this.highlighted) {
const template = '<mark class="asset-mark">$1</mark>'

this.innerHTML = this.url.replace(regExp, template)
this.innerHTML = this.name.replace(regExp, template)
} else {
this.textContent = this.url
this.textContent = this.name
}

this.classList.toggle('asset-link--highlighted', this.highlighted)
}

get name() {
return this.dataset.name
}

get type() {
if (this.classList.contains('asset-link--directory')) {
return 'directory'
Expand All @@ -33,8 +37,4 @@ export default class AssetLink extends CustomElement(HTMLAnchorElement) {

return ''
}

get url() {
return this.getAttribute('href')
}
}
13 changes: 10 additions & 3 deletions client/templates/main.xslt
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,30 @@
<li is="asset-item">
<xsl:attribute name="class">
<xsl:text>asset-item asset-item--</xsl:text>
<xsl:value-of select="name(.)" />
<xsl:value-of select="name()" />
</xsl:attribute>

<a is="asset-link">
<xsl:attribute name="aria-label">
<xsl:value-of select="name(.)" />
<xsl:value-of select="name()" />
<xsl:text> </xsl:text>
<xsl:value-of select="." />
</xsl:attribute>

<xsl:attribute name="data-name">
<xsl:value-of select="." />
</xsl:attribute>

<xsl:attribute name="href">
<xsl:value-of select="." />
<xsl:if test="name() = 'directory'">
<xsl:text>/</xsl:text>
</xsl:if>
</xsl:attribute>

<xsl:attribute name="class">
<xsl:text>asset-link asset-link--</xsl:text>
<xsl:value-of select="name(.)" />
<xsl:value-of select="name()" />
</xsl:attribute>

<xsl:value-of select="." />
Expand Down

0 comments on commit 0568104

Please sign in to comment.