Changeset f1627b6 in Klonkt for src/views/pages/news.ejs


Ignore:
Timestamp:
06/28/2026 02:40:46 PM (2 months ago)
Author:
Robin Genis <roboburr@…>
Branches:
main
Children:
127f87e
Parents:
fe9164f
Message:

feat(news): collapse long post bodies with a 'read more' toggle

Long post content in the News feed clamps to ~20em with a fade + a 'read more' button (added only
when the content overflows); click to expand/collapse.

  • views/pages/news.ejs — .tl-clamp + .tl-readmore + the toggle script
  • services/i18n.js — tl.read_more + tl.show_less (nl/en/de)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/views/pages/news.ejs

    rfe9164f rf1627b6  
    174174  .tl-content a { color: var(--accent, #06c); }
    175175  .tl-content img { max-width: 100%; height: auto; border-radius: 10px; background: #fff; }
     176  /* Long posts collapse to a max height with a fade + "read more" (added by JS only when it overflows). */
     177  .tl-content.tl-clamp { max-height: 20em; overflow: hidden;
     178    -webkit-mask-image: linear-gradient(180deg, #000 72%, transparent);
     179    mask-image: linear-gradient(180deg, #000 72%, transparent); }
     180  .tl-readmore { display: inline-block; margin: .15rem 0 .1rem; padding: .15rem 0;
     181    background: none; border: 0; color: var(--accent, #06c); font: inherit; font-weight: 600;
     182    font-size: .85rem; cursor: pointer; }
     183  .tl-readmore:hover { text-decoration: underline; }
    176184
    177185  /* Always show the FULL image at its natural ratio — never cropped, no letterbox. */
     
    267275})();
    268276</script>
     277
     278<script>
     279// Collapse long post bodies to a max height with a "read more" toggle — only when the content
     280// actually overflows. Runs on every /news render (full load + htmx swap); a per-element flag
     281// prevents double-wiring.
     282(function(){
     283  var RM = '<%= t("tl.read_more") %>', SL = '<%= t("tl.show_less") %>';
     284  document.querySelectorAll('.tl-content:not(.nsfw-media):not([data-rm])').forEach(function(c){
     285    c.setAttribute('data-rm', '1');
     286    if (c.scrollHeight > 360) {
     287      c.classList.add('tl-clamp');
     288      var b = document.createElement('button');
     289      b.type = 'button'; b.className = 'tl-readmore'; b.textContent = RM;
     290      b.addEventListener('click', function(){
     291        b.textContent = c.classList.toggle('tl-clamp') ? RM : SL;
     292      });
     293      c.insertAdjacentElement('afterend', b);
     294    }
     295  });
     296})();
     297</script>
Note: See TracChangeset for help on using the changeset viewer.