Skip to content

Commit

Permalink
update deps and add BASE_URL before action link in hero
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-xzq committed Aug 23, 2024
1 parent 5699743 commit dfd3767
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 34 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"removeDocFrontmatter": "node ./scripts/updateMdFrontmatter.mjs --type removeFrontmatter --scan-pattern './src/content/docs/**/*.md' --base-path cwd"
},
"dependencies": {
"@astrojs/starlight": "^0.25.5",
"astro": "^4.14.0",
"@astrojs/starlight": "^0.26.1",
"astro": "^4.14.5",
"sharp": "^0.32.5",
"starlight-image-zoom": "^0.7.0"
},
Expand Down
99 changes: 69 additions & 30 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions src/components/Hero.astro
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
---
import type { Props } from "@astrojs/starlight/props";
import Default from "@astrojs/starlight/components/Hero.astro";
import { removeDuplicateSlash } from "@/utils/index.ts";
const frontmatter = Astro.props.entry.data;
const actions = frontmatter.hero.actions;
const actions = frontmatter.hero?.actions ?? [];
// add BASE_URL before action link
for (const action of actions) {
if (action.link) {
action.link = removeDuplicateSlash(import.meta.env.BASE_URL + action.link);
}
}
---

<pre>{JSON.stringify(actions)}</pre>
<Default {...Astro.props}><slot /></Default>
4 changes: 4 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// 将多个 / 替换为一个 /
export const removeDuplicateSlash = (str: string) => {
return str.replace(/\/+/g, "/");
};

0 comments on commit dfd3767

Please sign in to comment.