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

imp: Display the links' tags and make them clickable #713

Merged
merged 3 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified locales/fr_FR/LC_MESSAGES/main.mo
Binary file not shown.
62 changes: 31 additions & 31 deletions locales/fr_FR/LC_MESSAGES/main.po
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
msgid ""
msgstr ""
"Project-Id-Version: Flus\n"
"POT-Creation-Date: 2024-10-17 17:36+0200\n"
"PO-Revision-Date: 2024-10-17 17:36+0200\n"
"POT-Creation-Date: 2024-10-17 18:52+0200\n"
"PO-Revision-Date: 2024-10-17 18:52+0200\n"
"Last-Translator: Marien Fressinaud <dev@marienfressinaud.fr>\n"
"Language-Team: \n"
"Language: fr_FR\n"
Expand Down Expand Up @@ -464,7 +464,7 @@ msgstr "< 1 min"
msgid "%s&nbsp;min"
msgstr "%s&nbsp;min"

#: utils/view_helpers.php:211 views/links/show.phtml:73
#: utils/view_helpers.php:211 views/links/show.phtml:83
msgid "you"
msgstr "vous"

Expand Down Expand Up @@ -676,7 +676,7 @@ msgstr "Page suivante"
#: views/links/collections/index.phtml:43 views/links/edit.phtml:44
#: views/links/edit.phtml:73 views/links/new.phtml:42 views/links/new.phtml:59
#: views/links/new.phtml:66 views/links/repairing/new.phtml:50
#: views/links/searches/show.phtml:54 views/links/show.phtml:206
#: views/links/searches/show.phtml:54 views/links/show.phtml:216
#: views/mastodon/show.phtml:77 views/mastodon/show.phtml:132
#: views/messages/edit.phtml:44 views/my/account/deletion.phtml:63
#: views/my/preferences/edit.phtml:41 views/my/profile/edit.phtml:56
Expand Down Expand Up @@ -1073,8 +1073,8 @@ msgid "Published by %s"
msgstr "Publiée par %s"

#: views/collections/show.phtml:74 views/collections/show_public.phtml:112
#: views/links/_link.phtml:221 views/links/_link.phtml:225
#: views/links/show.phtml:121 views/links/show.phtml:125
#: views/links/_link.phtml:231 views/links/_link.phtml:235
#: views/links/show.phtml:131 views/links/show.phtml:135
#: views/news/index.phtml:41 views/news/index.phtml:129
#: views/news/index.phtml:213
msgid "Actions"
Expand All @@ -1085,8 +1085,8 @@ msgid "Adjust for the news"
msgstr "Régler pour le journal"

#: views/collections/show.phtml:122 views/groups/_group.phtml:23
#: views/groups/_group.phtml:37 views/links/_link.phtml:273
#: views/links/show.phtml:141 views/profiles/show.phtml:55
#: views/groups/_group.phtml:37 views/links/_link.phtml:283
#: views/links/show.phtml:151 views/profiles/show.phtml:55
msgid "Edit"
msgstr "Modifier"

Expand Down Expand Up @@ -1116,8 +1116,8 @@ msgstr ""
"Êtes-vous sur·e de vouloir supprimer cette collection ? Vous pourriez perdre "
"les liens qui lui sont attachés."

#: views/collections/show.phtml:194 views/links/_link.phtml:311
#: views/links/show.phtml:158
#: views/collections/show.phtml:194 views/links/_link.phtml:321
#: views/links/show.phtml:168
msgid "Delete"
msgstr "Supprimer"

Expand Down Expand Up @@ -1447,7 +1447,7 @@ msgstr ""
"Des pisteurs ont été détectés dans ce lien, votre vie privée pourrait ne pas "
"être respectée si vous cliquez dessus."

#: views/links/_link.phtml:139 views/links/show.phtml:64
#: views/links/_link.phtml:139 views/links/show.phtml:74
msgid "ongoing synchronisation…"
msgstr "synchronisation en cours…"

Expand Down Expand Up @@ -1481,50 +1481,50 @@ msgstr ""
msgid "via <strong><a class=\"anchor--hidden\" href=\"%s\">%s</a></strong>"
msgstr "via <strong><a class=\"anchor--hidden\" href=\"%s\">%s</a></strong>"

#: views/links/_link.phtml:189
#: views/links/_link.phtml:199
#, php-format
msgid "%s comment"
msgid_plural "%s comments"
msgstr[0] "%s commentaire"
msgstr[1] "%s commentaires"

#: views/links/_link.phtml:194
#: views/links/_link.phtml:204
msgid "hidden"
msgstr "masqué"

#: views/links/_link.phtml:208
#: views/links/_link.phtml:218
msgid "Comments"
msgstr "Commentaires"

#: views/links/_link.phtml:237
#: views/links/_link.phtml:247
msgid "Remove from the news"
msgstr "Retirer du journal"

#: views/links/_link.phtml:254
#: views/links/_link.phtml:264
msgid "Copy the external link"
msgstr "Copier le lien externe"

#: views/links/_link.phtml:288
#: views/links/_link.phtml:298
msgid "Repair"
msgstr "Réparer"

#: views/links/_link.phtml:299
#: views/links/_link.phtml:309
msgid "Are you sure that you want to delete this link?"
msgstr "Êtes-vous sur·e de vouloir supprimer ce lien ?"

#: views/links/_link.phtml:323 views/links/_link.phtml:326
#: views/links/_link.phtml:333 views/links/_link.phtml:336
msgid "Mark as read"
msgstr "Marquer comme lu"

#: views/links/_link.phtml:336 views/links/_link.phtml:339
#: views/links/_link.phtml:346 views/links/_link.phtml:349
msgid "Remove from read list"
msgstr "Retirer des liens lus"

#: views/links/_link.phtml:349 views/links/_link.phtml:352
#: views/links/_link.phtml:359 views/links/_link.phtml:362
msgid "Read later"
msgstr "Lire plus tard"

#: views/links/_link.phtml:365 views/links/_link.phtml:369
#: views/links/_link.phtml:375 views/links/_link.phtml:379
#: views/links/collections/index.phtml:181
msgid "Store the link"
msgstr "Ranger le lien"
Expand All @@ -1541,16 +1541,16 @@ msgstr "Collections"
msgid "You already commented this link."
msgstr "Vous avez déjà commenté ce lien."

#: views/links/collections/index.phtml:113 views/links/show.phtml:190
#: views/links/collections/index.phtml:113 views/links/show.phtml:200
msgid "Anything else to add?"
msgstr "Des choses à ajouter ?"

#: views/links/collections/index.phtml:137
#: views/links/collections/index.phtml:170 views/links/show.phtml:223
#: views/links/collections/index.phtml:170 views/links/show.phtml:233
msgid "Share on Mastodon"
msgstr "Partager vers Mastodon"

#: views/links/collections/index.phtml:146 views/links/show.phtml:188
#: views/links/collections/index.phtml:146 views/links/show.phtml:198
msgid "What do you think?"
msgstr "Qu’en pensez-vous ?"

Expand Down Expand Up @@ -1666,28 +1666,28 @@ msgstr "Un lien partagé par %s sur %s."
msgid "Syndication feed of comments on %s"
msgstr "Flux de syndication de commentaires sur %s"

#: views/links/show.phtml:74
#: views/links/show.phtml:84
#, php-format
msgid "Added by <a href=\"%s\">%s</a>"
msgstr "Ajouté par <a href=\"%s\">%s</a>"

#: views/links/show.phtml:85
#: views/links/show.phtml:95
msgid "read"
msgstr "lire"

#: views/links/show.phtml:87
#: views/links/show.phtml:97
msgid "(open a new window)"
msgstr "(ouvre une nouvelle fenêtre)"

#: views/links/show.phtml:150
#: views/links/show.phtml:160
msgid "Are you sure that you want to delete this message?"
msgstr "Êtes-vous sur·e de vouloir supprimer ce message ?"

#: views/links/show.phtml:230
#: views/links/show.phtml:240
msgid "Comment"
msgstr "Commenter"

#: views/links/show.phtml:237
#: views/links/show.phtml:247
msgid "This link being hidden, the comments are private."
msgstr "Ce lien étant masqué, les commentaires sont privés."

Expand Down
1 change: 1 addition & 0 deletions src/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
@import './components/pagination.css';
@import './components/popup.css';
@import './components/sections.css';
@import './components/tags.css';
@import './components/titles.css';
@import './custom/collections.css';
@import './custom/collections-selector.css';
Expand Down
13 changes: 13 additions & 0 deletions src/assets/stylesheets/components/tags.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.tag {
overflow: hidden;

padding: 0 var(--space-smaller);

color: var(--color-turquoise-8);
font-size: var(--size-small);
text-decoration: none;
text-overflow: ellipsis;

background-color: var(--color-turquoise-2);
border-radius: var(--radius);
}
12 changes: 12 additions & 0 deletions src/assets/stylesheets/custom/links.css
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,18 @@
}
}

.link__tags {
display: flex;

gap: var(--space-smaller);

flex-wrap: wrap;
}

.link__tags--center {
justify-content: center;
}

.link__text {
margin-top: var(--space-small);
margin-bottom: var(--space-small);
Expand Down
1 change: 1 addition & 0 deletions src/services/LinkTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public static function refresh(models\Link $link): void
}

$tags = array_unique($tags);
$tags = array_values($tags);

$link->tags = $tags;

Expand Down
53 changes: 51 additions & 2 deletions src/utils/MiniMarkdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace App\utils;

use App\services;

/**
* An extension to the Parsedown library.
*
Expand Down Expand Up @@ -30,8 +32,55 @@ class MiniMarkdown extends \Parsedown

public function __construct()
{
$this->setSafeMode(true)
->setBreaksEnabled(true);
$this->setSafeMode(true);
$this->setBreaksEnabled(true);

$this->InlineTypes['#'][] = 'Tag';

$this->inlineMarkerList .= '#';
}

/**
* Make sure to block header tag so it doesn't conflict with lines starting
* with a #tag.
*
* @param array{body: string, indent: int, text: string} $line
*
* @return ?array<string, mixed>
*/
protected function blockHeader($line): ?array
{
return null;
}

/**
* @param array{text: string, context: string} $excerpt
*
* @return ?array<string, mixed>
*/
protected function inlineTag(array $excerpt): ?array
{
$result = preg_match(services\LinkTags::TAG_REGEX, $excerpt['text'], $matches);

if ($result) {
$tag = $matches['tag'];
$tag_url = \Minz\Url::for('links', [
'q' => "#{$tag}",
]);

return array(
'extent' => strlen($tag) + 1,
'element' => array(
'name' => 'a',
'text' => "#{$tag}",
'attributes' => array(
'href' => $tag_url,
),
),
);
} else {
return null;
}
}

/**
Expand Down
10 changes: 10 additions & 0 deletions src/views/links/_link.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,16 @@
</p>
<?php endif; ?>

<?php if ($link->tags && $beta_enabled): ?>
<div class="link__tags">
<?php foreach ($link->tags as $tag): ?>
<a class="tag" href="<?= url('links', ['q' => "#{$tag}"]) ?>">
#<?= $tag ?>
</a>
<?php endforeach; ?>
</div>
<?php endif; ?>

<?php if ($display_comments): ?>
<p class="link__text">
<a href="<?= url('link', ['id' => $link->id]) ?>">
Expand Down
10 changes: 10 additions & 0 deletions src/views/links/show.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@
</h1>
</div>

<?php if ($link->tags && $beta_enabled): ?>
<div class="link__tags link__tags--center">
<?php foreach ($link->tags as $tag): ?>
<a class="tag" href="<?= url('links', ['q' => "#{$tag}"]) ?>">
#<?= $tag ?>
</a>
<?php endforeach; ?>
</div>
<?php endif; ?>

<p class="section__intro">
<?php if (!$link->fetched_at): ?>
<span>
Expand Down
Loading