Repository navigation
Fix/edit this page #8250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Pranav-Kunjir
wants to merge
12
commits into
layer5io:master
Choose a base branch
from
Pranav-Kunjir:fix/edit-this-page
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Fix/edit this page #8250
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
614bd95
fix-edit-this-page-url
Pranav-Kunjir 3ac101c
fix-edit-this-page-url
Pranav-Kunjir 5db4919
fix-edit-this-page-url-implement-suggestion
Pranav-Kunjir 7c8544c
fix: verify raw and decoded content paths against repo root
Pranav-Kunjir d44ee92
fix: reject queryless template components as edit sources
Pranav-Kunjir 21e6b2d
Merge branch 'master' into fix/edit-this-page
Pranav-Kunjir 3bdf6e2
fix-edit-this-page-url-implement-suggestion-code-rabbit-improvement
Pranav-Kunjir c6284ac
Merge branch 'layer5io:master' into fix/edit-this-page
Pranav-Kunjir 067c753
re-run-pipeline
Pranav-Kunjir 0016dee
re-run-pipeline
Pranav-Kunjir 8222da6
Merge branch 'layer5io:master' into fix/edit-this-page
Pranav-Kunjir 448ba3e
fix: always emit blob links and revert unrelated formatting
Pranav-Kunjir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| import React from "react"; | ||
| import Layout from "./src/components/layout.js"; | ||
|
|
||
| export const wrapPageElement = ({ element }) => ( | ||
| <Layout> | ||
| export const wrapPageElement = ({ element, props }) => ( | ||
| <Layout pageContext={props.pageContext}> | ||
| {element} | ||
| </Layout> | ||
| ); | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /* eslint-env node */ | ||
|
|
||
| const fs = require("fs"); | ||
| const path = require("path"); | ||
|
|
||
| const REPO = "layer5io/layer5"; | ||
| const IGNORED = new Set([".cache", "public", "node_modules", ".git"]); | ||
| const CONTENT_PARAM = "__contentFilePath="; | ||
|
|
||
| const decodePath = (raw) => { | ||
| try { | ||
| return decodeURIComponent(raw); | ||
| } catch { | ||
| return raw; | ||
| } | ||
| }; | ||
|
|
||
| const sourceFromComponent = (component, root) => { | ||
| if (typeof component !== "string") return ""; | ||
| const q = component.indexOf("?"); | ||
| if (q === -1) return component; | ||
|
|
||
| const query = component.slice(q + 1); | ||
| const start = query.indexOf(CONTENT_PARAM); | ||
| if (start === -1) return component.slice(0, q); | ||
|
|
||
| const raw = query.slice(start + CONTENT_PARAM.length); | ||
| const exportAt = raw.indexOf("&export="); | ||
| const contentPath = exportAt === -1 ? raw : raw.slice(0, exportAt); | ||
|
|
||
| const decoded = decodePath(contentPath); | ||
| if (decoded !== contentPath && root) { | ||
| const resolve = (candidate) => | ||
| path.isAbsolute(candidate) ? candidate : path.resolve(root, candidate); | ||
| if (fs.existsSync(resolve(contentPath))) return contentPath; | ||
| if (fs.existsSync(resolve(decoded))) return decoded; | ||
| } | ||
|
|
||
| return decoded || component.slice(0, q); | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| }; | ||
|
|
||
| const toEditUrl = (component, root) => { | ||
| const src = sourceFromComponent(component || "", root); | ||
| if (!src) return null; | ||
|
|
||
| const abs = path.isAbsolute(src) ? src : path.resolve(root, src); | ||
| const hasContentPath = | ||
| typeof component === "string" && component.includes(CONTENT_PARAM); | ||
| const templatesRoot = path.resolve(root, "src", "templates"); | ||
| if ( | ||
| !hasContentPath && | ||
| (abs === templatesRoot || abs.startsWith(`${templatesRoot}${path.sep}`)) | ||
| ) { | ||
| return null; | ||
| } | ||
|
|
||
| const rel = path.relative(root, abs); | ||
| if (!rel || rel === ".." || rel.startsWith(`..${path.sep}`)) return null; | ||
| if (path.isAbsolute(rel)) return null; | ||
| if (rel.split(path.sep).some((seg) => IGNORED.has(seg))) return null; | ||
| if (!fs.existsSync(abs)) return null; | ||
|
|
||
| const encoded = rel.split(path.sep).map(encodeURIComponent).join("/"); | ||
| return `https://github.com/${REPO}/blob/master/${encoded}`; | ||
| }; | ||
|
|
||
| module.exports = { sourceFromComponent, toEditUrl }; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.