patx/gitman

Unify activity and profile repository cards with notifications

Commit e270558 · patx · Nov 3 at 8:41PM

Changeset
e270558fa0c46baa20bdcfc22bdc9be63488de95
Parents
308b118966fb00da660c9da6be5f012d48095e41

View source at this commit

Comments

No comments yet.

Log in to comment

Diff

diff --git a/app.py b/app.py
index d1d386f..395b19b 100644
--- a/app.py
+++ b/app.py
@@ -2743,7 +2743,7 @@ def render_markdown(text):
     )
 
 
-def render_markdown_links(text):
+def render_markdown_links(text, *, links=True):
     rendered = markdown.markdown(
         html.escape(text or "", quote=False),
         extensions=[profile_mentions()],
@@ -2751,7 +2751,7 @@ def render_markdown_links(text):
     )
     return bleach.clean(
         rendered,
-        tags=MARKDOWN_LINK_TAGS,
+        tags=MARKDOWN_LINK_TAGS if links else set(),
         attributes=MARKDOWN_LINK_ATTRIBUTES,
         protocols={"http", "https", "mailto"},
         strip=True,
diff --git a/static/styles.css b/static/styles.css
index 0eff9b6..6fc599a 100644
--- a/static/styles.css
+++ b/static/styles.css
@@ -129,7 +129,7 @@ button:active, .button:active {
 form button[type="submit"] { justify-self: start; }
 
 @media (prefers-reduced-motion: no-preference) {
-  button, .button, .nav-icons, .repo-search-link, .ref-picker-option, .ref-picker-toggle, .mention-option {
+  .feed-card, button, .button, .nav-icons, .repo-search-link, .ref-picker-option, .ref-picker-toggle, .mention-option {
     transition: background-color 150ms ease, color 150ms ease;
   }
 }
@@ -323,7 +323,7 @@ th { color: var(--ink); font-weight: 700; }
   margin: 0;
   list-style: none;
 }
-.repo-list { gap: 1.5rem; }
+.repo-list { gap: 1rem; }
 .commit-list, .comment-list { gap: 1.25rem; }
 .commit-list li > div > :last-child { margin-bottom: 0; }
 .commit-list li strong, .commit-list li small { display: block; }
@@ -336,8 +336,7 @@ th { color: var(--ink); font-weight: 700; }
 .meta-list dd { margin: 0; overflow-x: auto; }
 
 .activity-feed { gap: 1rem; }
-.activity-feed li { padding-bottom: 1rem; border-bottom: 1px solid var(--surface-border); }
-.activity-feed li:last-child { border-bottom: 0; }
+.activity-feed > li { padding: 0; border: 0; min-width: 0; }
 .activity-title, .activity-detail { margin-bottom: .25rem; }
 .activity-detail { color: var(--text); }
 
@@ -572,9 +571,8 @@ th { color: var(--ink); font-weight: 700; }
   line-height: 1;
   text-align: center;
 }
-.notification-feed > li { padding: 0; border: 0; }
 .notification-feed form { display: block; }
-.notification-card {
+.feed-card {
   display: block;
   width: 100%;
   padding: 1.25rem;
@@ -587,15 +585,16 @@ th { color: var(--ink); font-weight: 700; }
   line-height: 1.6;
   overflow-wrap: anywhere;
 }
-.notification-card > span { display: block; margin: 0; }
-.notification-card > span + span { margin-top: .5rem; }
-.notification-card .activity-title { color: var(--ink); }
+.feed-card > span { display: block; margin: 0; }
+.feed-card > span + span { margin-top: .5rem; }
+.feed-card .activity-title { color: var(--ink); }
 .notification-card.notification-unread { background: var(--code-bg); }
-.notification-card:hover, .notification-card:active {
+.feed-card:hover, .feed-card:active {
   background: var(--chip);
   color: var(--text);
+  text-decoration: none;
 }
-.notification-card:focus-visible { outline-offset: 3px; }
+.feed-card:focus-visible { outline-offset: 3px; }
 .mention-option:hover small, .mention-option.active small { color: inherit; }
 
 @media (max-width: 760px) {
diff --git a/templates/activity_card_content.tpl b/templates/activity_card_content.tpl
new file mode 100644
index 0000000..b6e152d
--- /dev/null
+++ b/templates/activity_card_content.tpl
@@ -0,0 +1,10 @@
+<span class="activity-title"><strong>{{action['actor_label']}}</strong> {{action['summary']}} <strong>{{action['target_label']}}</strong></span>
+<span class="muted">
+  % if show_repo_context:
+    in {{action['repo_owner_username']}}/{{action['repo_name']}} ·
+  % end
+  {{action['occurred_at']}}
+</span>
+% if action['detail']:
+  <span class="activity-detail">{{!render_markdown_links(action['detail'], links=False)}}</span>
+% end
diff --git a/templates/activity_feed.tpl b/templates/activity_feed.tpl
index a0f8177..43ebff1 100644
--- a/templates/activity_feed.tpl
+++ b/templates/activity_feed.tpl
@@ -1,30 +1,15 @@
-    <ol class="activity-feed{{' notification-feed' if get('notifications_feed', False) else ''}}" data-paginated-list>
-      % for action in actions:
-        % repo_url = "/" + action["repo_owner_username"] + "/" + action["repo_name"] if action["repo_owner_username"] and action["repo_name"] else ""
-        % show_repo_context = repo_url and action["target_url"] != repo_url
-        <li>
-          % if get('notifications_feed', False):
-            % include('notification_card.tpl', action=action, show_repo_context=show_repo_context)
-          % else:
-          <p class="activity-title">
-            % if action["actor_url"]:
-              <strong><a href="{{action['actor_url']}}">{{action["actor_label"]}}</a></strong>
-            % else:
-              <strong>{{action["actor_label"]}}</strong>
-            % end
-            {{action["summary"]}}
-            <a href="{{action['target_url']}}">{{action["target_label"]}}</a>
-          </p>
-          <p class="muted">
-            % if show_repo_context:
-              in <a href="{{repo_url}}">{{action["repo_owner_username"]}}/{{action["repo_name"]}}</a> ·
-            % end
-            {{action["occurred_at"]}}
-          </p>
-          % if action["detail"]:
-            <p class="activity-detail">{{!render_markdown_links(action["detail"])}}</p>
-          % end
-          % end
-        </li>
+<ol class="activity-feed{{' notification-feed' if get('notifications_feed', False) else ''}}" data-paginated-list>
+  % for action in actions:
+    % repo_url = "/" + action["repo_owner_username"] + "/" + action["repo_name"] if action["repo_owner_username"] and action["repo_name"] else ""
+    % show_repo_context = repo_url and action["target_url"] != repo_url
+    <li>
+      % if get('notifications_feed', False):
+        % include('notification_card.tpl', action=action, show_repo_context=show_repo_context)
+      % else:
+        <a class="feed-card" href="{{action['target_url']}}" aria-label="{{action['actor_label']}} {{action['summary']}} {{action['target_label']}}">
+          % include('activity_card_content.tpl', action=action, show_repo_context=show_repo_context)
+        </a>
       % end
-    </ol>
+    </li>
+  % end
+</ol>
diff --git a/templates/base.tpl b/templates/base.tpl
index 1f2b960..e8f51eb 100644
--- a/templates/base.tpl
+++ b/templates/base.tpl
@@ -11,7 +11,7 @@
   <link rel="icon" type="image/svg+xml" href="/static/git.svg">
   <link rel="stylesheet" href="/static/vendor/highlight.js/github.min.css">
   <link rel="stylesheet" href="/static/vendor/highlight.js/github-dark.min.css" media="(prefers-color-scheme: dark)">
-  <link rel="stylesheet" href="/static/styles.css?v=13">
+  <link rel="stylesheet" href="/static/styles.css?v=14">
 </head>
 <body>
   <header class="site-header">
diff --git a/templates/notification_card.tpl b/templates/notification_card.tpl
index 89b4075..e7a0e01 100644
--- a/templates/notification_card.tpl
+++ b/templates/notification_card.tpl
@@ -3,16 +3,7 @@
   <input type="hidden" name="notification_key" value="{{action['event_key']}}">
   <input type="hidden" name="signature" value="{{action['read_signature']}}">
   <input type="hidden" name="target" value="{{action['target_url']}}">
-  <button class="notification-card{{' notification-unread' if not action['is_read'] else ''}}" type="submit" aria-label="{{'Unread notification: ' if not action['is_read'] else 'Notification: '}}{{action['actor_label']}} {{action['summary']}} {{action['target_label']}}">
-    <span class="activity-title"><strong>{{action['actor_label']}}</strong> {{action['summary']}} <strong>{{action['target_label']}}</strong></span>
-    <span class="muted">
-      % if show_repo_context:
-        in {{action['repo_owner_username']}}/{{action['repo_name']}} ·
-      % end
-      {{action['occurred_at']}}
-    </span>
-    % if action['detail']:
-      <span class="activity-detail">{{action['detail']}}</span>
-    % end
+  <button class="feed-card notification-card{{' notification-unread' if not action['is_read'] else ''}}" type="submit" aria-label="{{'Unread notification: ' if not action['is_read'] else 'Notification: '}}{{action['actor_label']}} {{action['summary']}} {{action['target_label']}}">
+    % include('activity_card_content.tpl', action=action, show_repo_context=show_repo_context)
   </button>
 </form>
diff --git a/templates/profile.tpl b/templates/profile.tpl
index 25f1ef0..84449fa 100644
--- a/templates/profile.tpl
+++ b/templates/profile.tpl
@@ -34,14 +34,11 @@
   % if repos:
     <div class="repo-list" data-paginated-list>
       % for repo in repos:
-        <div>
-          <a href="/{{repo['owner_username']}}/{{repo['name']}}">
-            <strong>{{repo["owner_username"]}}/{{repo["name"]}}</strong></a>
-            <br>
-            {{!render_markdown_links(repo["description"]) or "No description yet."}}
-            <br>
-            <small>Updated {{repo["updated_at"]}} · {{repo["star_count"]}} stars</small>
-        </div>
+        <a class="feed-card repo-card" href="/{{repo['owner_username']}}/{{repo['name']}}">
+          <span class="activity-title"><strong>{{repo['owner_username']}}/{{repo['name']}}</strong></span>
+          <span class="activity-detail">{{!render_markdown_links(repo['description'], links=False) or 'No description yet.'}}</span>
+          <span class="muted">Updated {{repo['updated_at']}} · {{repo['star_count']}} stars</span>
+        </a>
       % end
     </div>
       % include("pagination.tpl", pagination=pagination)
diff --git a/tests/test_app.py b/tests/test_app.py
index 95a0261..f04e4ce 100644
--- a/tests/test_app.py
+++ b/tests/test_app.py
@@ -472,6 +472,9 @@ def test_render_markdown_links_allows_only_links():
     rendered = gitman.render_markdown_links("[site](https://example.com) **bold** <strong>x</strong>")
 
     assert rendered == '<a href="https://example.com">site</a> bold &lt;strong&gt;x&lt;/strong&gt;'
+    card_text = gitman.render_markdown_links("[site](https://example.com) **bold** <strong>x</strong>", links=False)
+    assert card_text == 'site bold &lt;strong&gt;x&lt;/strong&gt;'
+
 
 
 def test_startup_config_rejects_default_secret_outside_debug(monkeypatch):