Skip to content

fix: include site name in members CSV export filename (#28310)#28362

Open
amal-hafis wants to merge 1 commit into
TryGhost:mainfrom
amal-hafis:fix/members-csv-filename
Open

fix: include site name in members CSV export filename (#28310)#28362
amal-hafis wants to merge 1 commit into
TryGhost:mainfrom
amal-hafis:fix/members-csv-filename

Conversation

@amal-hafis
Copy link
Copy Markdown

Why are you making it?

The members CSV export filename did not include the site name, unlike the JSON export and the already-fixed analytics CSV export (#28227). This inconsistency makes it harder to identify which site the data comes from when managing multiple Ghost instances.

What does it do?

Updates the members CSV export filename to follow the same convention:
<site-name>.ghost.members.YYYY-MM-DD.csv

Falls back to ghost.members.YYYY-MM-DD.csv if no site title is set.

Why is this something Ghost users need?

Consistency across all exports and easier file management when handling multiple Ghost sites.


  • I've read and followed the Contributor Guide
  • I've explained my change
  • I've written an automated test to prove my change works

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 4, 2026

Review Change Stack

Walkthrough

The members API endpoint now imports slugify from @tryghost/string and updates the CSV export filename construction. The exportCSV endpoint generates filenames with an optional slugified site title prefix: when a site title is available, filenames become {titlePrefix}ghost.members.{YYYY-MM-DD}.csv; otherwise they remain ghost.members.{YYYY-MM-DD}.csv.

Possibly related issues

  • TryGhost/Ghost#28310: Directly implements the requested feature of adding a slugified site title prefix to members CSV export filenames.

Possibly related PRs

  • TryGhost/Ghost#28308: Applies the same pattern of updating CSV export filenames to include slugified site-title prefixes across another export endpoint.

Suggested reviewers

  • sagzy
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: including the site name in the members CSV export filename, directly matching the file modification in the changeset.
Description check ✅ Passed The description is well-related to the changeset, explaining the rationale (inconsistency with JSON and analytics exports), the specific change (new filename format), and the fallback behavior.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@ghost/core/core/server/api/endpoints/members.js`:
- Around line 383-384: Compute the slug once and base the fallback on the slug
result (not raw title): call slugify(title) into a local variable (e.g., slug),
then set titlePrefix = slug ? `${slug}.` : '' so you avoid emitting a leading
dot when slugify(title) returns an empty string; keep the existing return
`${titlePrefix}ghost.members.${datetime}.csv`.
- Around line 382-385: The endpoint builds a prefixed filename (the const that
returns `${titlePrefix}ghost.members.${datetime}.csv`) but the stream serializer
membersCsvSerializer in serializers/output/members.js still hardcodes
Content-Disposition to `members.{YYYY-MM-DD}.csv`, so the header is overridden;
update the stream serializer to accept a filename option (or read
resp.locals.filename) and use that value when setting Content-Disposition, and
update the members endpoint (where the filename is constructed) to pass the
computed filename into membersCsvSerializer (or set resp.locals.filename) so the
serializer uses the endpoint-provided name rather than the hardcoded one.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ed613f9f-887a-4600-b537-34812b2d4aa3

📥 Commits

Reviewing files that changed from the base of the PR and between 25736d4 and 9c91ab8.

📒 Files selected for processing (1)
  • ghost/core/core/server/api/endpoints/members.js

Comment on lines +382 to 385
const title = settingsCache.get('title');
const titlePrefix = title ? `${slugify(title)}.` : '';
return `${titlePrefix}ghost.members.${datetime}.csv`;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Filename prefix logic may never reach clients because CSV serializer hardcodes Content-Disposition.

At Line 384 you return a prefixed filename, but ghost/core/core/server/api/endpoints/utils/serializers/output/members.js (Lines 469-493 in provided context) still sets Content-Disposition to members.{YYYY-MM-DD}.csv. If that stream serializer runs for this endpoint, it overrides this PR’s header contract and the new filename format won’t be applied.

Suggested fix (propagate endpoint filename into stream serializer)
# ghost/core/core/server/api/endpoints/utils/serializers/output/members.js
-            res.setHeader('Content-Disposition', `attachment; filename="members.${datetime}.csv"`);
+            const fallbackFilename = `members.${datetime}.csv`;
+            const disposition = res.getHeader('Content-Disposition');
+            if (!disposition) {
+                res.setHeader('Content-Disposition', `attachment; filename="${fallbackFilename}"`);
+            }
# ghost/core/core/server/api/endpoints/members.js
                 value() {
                     const datetime = (new Date()).toJSON().substring(0, 10);
                     const title = settingsCache.get('title');
                     const titlePrefix = title ? `${slugify(title)}.` : '';
                     return `${titlePrefix}ghost.members.${datetime}.csv`;
                 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ghost/core/core/server/api/endpoints/members.js` around lines 382 - 385, The
endpoint builds a prefixed filename (the const that returns
`${titlePrefix}ghost.members.${datetime}.csv`) but the stream serializer
membersCsvSerializer in serializers/output/members.js still hardcodes
Content-Disposition to `members.{YYYY-MM-DD}.csv`, so the header is overridden;
update the stream serializer to accept a filename option (or read
resp.locals.filename) and use that value when setting Content-Disposition, and
update the members endpoint (where the filename is constructed) to pass the
computed filename into membersCsvSerializer (or set resp.locals.filename) so the
serializer uses the endpoint-provided name rather than the hardcoded one.

Comment on lines +383 to +384
const titlePrefix = title ? `${slugify(title)}.` : '';
return `${titlePrefix}ghost.members.${datetime}.csv`;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Guard against empty slug output to preserve the documented fallback filename.

At Line 383, fallback is based on raw title truthiness. If title exists but slugifies to an empty string, Line 384 can emit .ghost.members.{date}.csv instead of ghost.members.{date}.csv.

Suggested fix (fallback on slug result, not raw title)
-                    const title = settingsCache.get('title');
-                    const titlePrefix = title ? `${slugify(title)}.` : '';
+                    const title = settingsCache.get('title');
+                    const titleSlug = title ? slugify(title) : '';
+                    const titlePrefix = titleSlug ? `${titleSlug}.` : '';
                     return `${titlePrefix}ghost.members.${datetime}.csv`;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ghost/core/core/server/api/endpoints/members.js` around lines 383 - 384,
Compute the slug once and base the fallback on the slug result (not raw title):
call slugify(title) into a local variable (e.g., slug), then set titlePrefix =
slug ? `${slug}.` : '' so you avoid emitting a leading dot when slugify(title)
returns an empty string; keep the existing return
`${titlePrefix}ghost.members.${datetime}.csv`.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant