Skip to content

Fixed stats url for subdirectory sites#22654

Merged
9larsons merged 3 commits intomainfrom
fix-stats-subdir
Mar 26, 2025
Merged

Fixed stats url for subdirectory sites#22654
9larsons merged 3 commits intomainfrom
fix-stats-subdir

Conversation

@9larsons
Copy link
Contributor

no ref

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 26, 2025

Walkthrough

The changes in the getTinybirdTrackerScript function involve the introduction of a new variable src, which constructs the source URL for the script by concatenating the result of urlUtils.getSubdir() with the string '/public/ghost-stats.js'. This variable is then used in the return statement to dynamically set the src attribute of the script tag. The previous hardcoded string "/public/ghost-stats.js" has been replaced with this new variable, ensuring that the script source is now derived from the utility function rather than being a static path. The error handling and overall structure of the function remain unchanged, with the same parameters and return type. Additionally, a new test case has been added to verify that the helper function correctly includes the tracker script when a subdirectory is specified in the configuration URL.

Possibly related PRs


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4e1ae2a and 36a2fc0.

⛔ Files ignored due to path filters (1)
  • ghost/core/test/unit/frontend/helpers/__snapshots__/ghost_head.test.js.snap is excluded by !**/*.snap
📒 Files selected for processing (1)
  • ghost/core/test/unit/frontend/helpers/ghost_head.test.js (1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
ghost/core/test/unit/frontend/helpers/ghost_head.test.js (6)
ghost/core/test/integration/url_service.test.js (1)
  • configUtils (4-4)
ghost/core/test/unit/frontend/helpers/recommendations.test.js (1)
  • configUtils (6-6)
ghost/core/test/unit/server/data/db/backup.test.js (1)
  • configUtils (7-7)
ghost/core/test/unit/frontend/helpers/get.test.js (1)
  • configUtils (5-5)
ghost/core/test/unit/server/models/member.test.js (1)
  • configUtils (4-4)
ghost/core/test/unit/server/models/permission.test.js (1)
  • configUtils (4-4)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: Ghost-CLI tests
  • GitHub Check: Database tests (Node 20.11.1, sqlite3)
  • GitHub Check: Database tests (Node 22.13.1, mysql8)
  • GitHub Check: Unit tests (Node 22.13.1)
  • GitHub Check: Database tests (Node 20.11.1, mysql8)
  • GitHub Check: Regression tests (Node 20.11.1, mysql8)
  • GitHub Check: Unit tests (Node 20.11.1)
  • GitHub Check: Database tests (Node 18.12.1, mysql8)
  • GitHub Check: Unit tests (Node 18.12.1)
🔇 Additional comments (1)
ghost/core/test/unit/frontend/helpers/ghost_head.test.js (1)

1478-1490: Good implementation of subdirectory test case!

This test case correctly verifies that the ghost_head helper includes the tracker script with the proper subdirectory path when a site is hosted in a subdirectory. It properly sets the configuration URL to include a subdirectory and checks that the rendered output includes a script tag with the correct path.

This test complements the existing test for the tracker script and ensures that the fix for stats URLs in subdirectory sites works correctly.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
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: 0

🧹 Nitpick comments (1)
ghost/core/core/frontend/helpers/ghost_head.js (1)

154-155: Great fix for subdirectory installations!

This change correctly addresses the issue with stats URLs for Ghost sites hosted in subdirectories by dynamically constructing the script source URL using urlUtils.getSubdir(). This ensures the Tinybird tracker script works properly regardless of whether the site is installed at the root or in a subdirectory.

For additional robustness, you could consider using a path joining utility to handle potential edge cases with slashes:

-const src = urlUtils.getSubdir() + '/public/ghost-stats.js';
+const src = urlUtils.join(urlUtils.getSubdir(), '/public/ghost-stats.js');

This would ensure proper path formation even if the subdirectory path handling changes in the future.

Also applies to: 167-167

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 337dfc1 and 4e1ae2a.

📒 Files selected for processing (1)
  • ghost/core/core/frontend/helpers/ghost_head.js (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: Ghost-CLI tests
  • GitHub Check: Regression tests (Node 20.11.1, mysql8)
  • GitHub Check: Database tests (Node 20.11.1, sqlite3)
  • GitHub Check: Database tests (Node 22.13.1, mysql8)
  • GitHub Check: Database tests (Node 20.11.1, mysql8)
  • GitHub Check: Database tests (Node 18.12.1, mysql8)

@9larsons 9larsons enabled auto-merge (squash) March 26, 2025 21:04
@9larsons 9larsons merged commit 3973838 into main Mar 26, 2025
26 checks passed
@9larsons 9larsons deleted the fix-stats-subdir branch March 26, 2025 21:10
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