Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Generate & display image/PDF thumbnails for topic documents (put image_processing to use)

未关闭
#700 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
66/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
冷清
技术栈
rails, ruby

调研方向

从 Gemfile:13、app/views/topics/_topic.html.erb:17-38 和 app/helpers/topics_helper.rb 开始,然后找到 topic 文档附件声明和现有的 Active Storage 配置。完成的标准是:可表示的图像和 PDF 显示链接到原始文件的已缓存 256x256 缩略图,而其他预览或预览失败的情况保留通用图标;验证所需的系统依赖,并为 variant 和 fallback 情况增加覆盖。

由索引模型根据 Issue 内容生成。

描述

Requirements Incomplete

Background

The image_processing gem (Gemfile:13, ~> 1.14) is declared and locked (pulling in mini_magick + ruby-vips) but nothing in the app actually uses it — no Active Storage variants, previews, or representations anywhere in app/, app/views/, or config/. Topic documents are rendered as their original blobs only:

  • app/views/topics/_topic.html.erb:17-38 — the Documents section shows a generic file icon + filename link + Download button for every document, regardless of type.
  • app/helpers/topics_helper.rb — card_preview_media embeds the full-size original.

Rather than drop the gem, this issue puts it to work: generate small thumbnails for image and PDF documents and show them on the topic show page, falling back to the current icon for everything else.

This is a deliberately small, self-contained first slice. The nicer-but-heavier version (click-to-enlarge lightbox, eagerly generated variants) is captured under Future enhancements below and should be a separate follow-up.

Approach: lazy generation

Variants are generated lazily on first request (Active Storage's default) and cached. This is what keeps the task small:

  • No background job — no async infrastructure to build.
  • No backfill — lazy generation is the on-demand backfill. Existing documents get a thumbnail the first time someone views the topic; new ones the same way. Nothing is precomputed, so there's no "old documents lack a variant" gap and no migration/rake task.
  • No conditional-on-present logic — we simply render representation(:thumb) for representable documents and fall back to the icon for the rest.

Proposed work

1. Wiring — declare a :thumb variant on the attachment

Resize to 256x256.

  • Covers raster images directly. For PDFs, use the unified representation(:thumb) API, which routes images through variant and PDFs through preview (first page → image → resize).
  • Confirm config.active_storage.variant_processor = :vips (default; ruby-vips is already locked, so no ImageMagick dependency needed for images).

2. UI — thumbnail on the topic show page

In app/views/topics/_topic.html.erb, in the per-document block (lines 18-37), render the thumbnail in place of the generic SVG icon for representable documents, wrapped in a plain link that opens the original inline (new tab). Keep the filename link, size, and Download button exactly as they are.

3. System dependencies

  • Image variants: libvips (already implied by ruby-vips).
  • PDF previews: poppler-utils (pdftoppm) or mupdf must be present in CI and the deploy/Docker images, or PDF thumbnails fail (and fall back to the icon).
  • webp/avif/svg support depends on how libvips is built. Recommend excluding image/svg+xml from thumbnail generation (vector; rasterizing needs librsvg and adds little value) and verifying webp/avif on the target image before shipping.

Acceptance criteria

  • An image document on a topic shows a thumbnail on the topic show page (generated on first view, cached after).
  • A PDF document shows a first-page thumbnail.
  • Clicking a thumbnail opens the original image/PDF inline in a new tab.
  • Non-representable types (video/audio/other) and any document whose preview can't be generated fall back to the current generic icon — no errors.
  • Required system dependencies (libvips, poppler/mupdf) are available in CI and deploy images.
  • Tests cover: the :thumb variant is declared, the view renders a thumbnail for representable documents, and non-representable documents render the fallback icon.

Known tradeoffs (acceptable for a nonessential feature)

  • First-view latency — the first person to view a topic with a large image/PDF waits while the thumbnail generates; cached thereafter.
  • No proactive backfill — existing documents get thumbnails on first view rather than ahead of time. This is intentional.

Future enhancements (separate follow-up)

A nicer interaction, deferred to keep this task small. It can be added later with no backfill and no confusing UI change, because lazy generation makes any new variant available uniformly for all documents (old and new) the moment its consumer ships — so every thumbnail behaves the same, and the click target simply upgrades from "open in new tab" to "open lightbox":

  • Add a :medium variant (e.g. resize_to_limit: [1200, 1200]) for display in a lightbox/modal, so clicking a thumbnail doesn't load the full-resolution original (documents can be up to 200 MB per the Topic size validation).
  • Lightbox closes via backdrop and Esc; reuse an existing modal pattern if one exists.
  • Optionally, eagerly generate variants via a background job on upload to remove first-view latency. (Note: going eager is the point at which a backfill question for old documents would reappear — staying lazy avoids it.)
  • Unify TopicsHelper#card_preview_media to use representation(:thumb) for card/list previews instead of full-size originals.
主要语言
Ruby
星标
16
派生
11
PR 合并指标
30 天内没有已合并 PR

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

rubyforgood/skillrx 的其他 Issue

查看 rubyforgood/skillrx 的全部 Issue

相似的 Issue

更多 Ruby Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。