-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust Android Extension for Adobe Experience SDK v3 (#1170)
- Loading branch information
Showing
27 changed files
with
2,461 additions
and
178 deletions.
There are no files selected for viewing
This file contains 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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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,19 @@ | ||
--- | ||
import { fetchExampleApp } from "@components/utils/fetchExampleApp"; | ||
import { Code as ExpressiveCode } from "astro-expressive-code/components"; | ||
interface Props { | ||
permalink: string; | ||
lang: string; | ||
} | ||
const { permalink, lang } = Astro.props as Props; | ||
const { code, title } = await fetchExampleApp(permalink); | ||
const codeAttributes = { | ||
code, | ||
lang, | ||
title, | ||
}; | ||
--- | ||
|
||
<ExpressiveCode {...codeAttributes} /> |
This file contains 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 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 @@ | ||
import { Octokit } from "@octokit/core"; | ||
|
||
const octokit = new Octokit({ auth: import.meta.env.VITE_GITHUB_TOKEN }); | ||
|
||
/** | ||
* Parses a file URL and returns its component parts | ||
* @param fileUrl | ||
* @returns The component parts of the URL for use in a GraphQL query | ||
*/ | ||
function parsePermalink(fileUrl: string) { | ||
const regex = | ||
/https:\/\/github\.com\/([^\/]+)\/([^\/]+)\/blob\/([^\/]+)\/(.+)/; | ||
const match = fileUrl.match(regex); | ||
if (!match) { | ||
throw new Error("Invalid file URL format."); | ||
} | ||
|
||
const [, owner, repo, branch, filePath] = match; | ||
|
||
const filename = filePath.split("/").pop()!; | ||
|
||
return { owner, repo, branch, filePath, filename }; | ||
} | ||
|
||
/** | ||
* Fetches the text content of a file from GitHub | ||
* @param fileUrl | ||
* @returns The file name and contents | ||
*/ | ||
export async function fetchExampleApp( | ||
fileUrl: string, | ||
): Promise<{ code: string; title: string }> { | ||
const { owner, repo, branch, filePath, filename } = parsePermalink(fileUrl); | ||
|
||
const query = ` | ||
query($owner: String!, $repo: String!, $expression: String!) { | ||
repository(owner: $owner, name: $repo) { | ||
object(expression: $expression) { | ||
... on Blob { | ||
text | ||
} | ||
} | ||
} | ||
} | ||
`; | ||
|
||
const expression = `${branch}:${filePath}`; | ||
|
||
const variables = { owner, repo, expression }; | ||
|
||
try { | ||
const response = await octokit.graphql< | ||
{ repository: { object: { text: string } } } | ||
>(query, variables); | ||
|
||
if (!response.repository.object) { | ||
throw new Error("File not found in the repository."); | ||
} | ||
|
||
const { text: code } = response.repository.object; | ||
return { code, title: filename }; | ||
} catch (error) { | ||
throw new Error( | ||
`Failed to fetch file content: ${(error as Error).message}`, | ||
); | ||
} | ||
} |
Oops, something went wrong.