summaryrefslogtreecommitdiff
path: root/docs/src/pages/reference
diff options
context:
space:
mode:
authorGravatar Matthew Phillips <matthew@matthewphillips.info> 2021-08-16 16:43:06 -0400
committerGravatar GitHub <noreply@github.com> 2021-08-16 16:43:06 -0400
commit78b5bde14c167b289a20b479d4fa4790eb9165aa (patch)
tree3a86c1d8bea35dbe0012859452d1495381d010b0 /docs/src/pages/reference
parent47025a7c7d22870cdaaec9aefb38d79524ba339e (diff)
downloadastro-78b5bde14c167b289a20b479d4fa4790eb9165aa.tar.gz
astro-78b5bde14c167b289a20b479d4fa4790eb9165aa.tar.zst
astro-78b5bde14c167b289a20b479d4fa4790eb9165aa.zip
Astro.resolve (#1085)
* add: Astro.resolve * Add docs and tests for Astro.resolve * Add warnings when using string literals * Prevent windows errors * Adds a changeset * Use the astro logger to log the warning * Use the .js extension * Dont warn for data urls * Rename nonRelative and better match Co-authored-by: Jonathan Neal <jonathantneal@hotmail.com>
Diffstat (limited to 'docs/src/pages/reference')
-rw-r--r--docs/src/pages/reference/api-reference.md24
1 files changed, 24 insertions, 0 deletions
diff --git a/docs/src/pages/reference/api-reference.md b/docs/src/pages/reference/api-reference.md
index 148241691..2f73cb30c 100644
--- a/docs/src/pages/reference/api-reference.md
+++ b/docs/src/pages/reference/api-reference.md
@@ -64,6 +64,30 @@ const data = Astro.fetchContent('../pages/post/*.md'); // returns an array of po
`Astro.site` returns a `URL` made from `buildOptions.site` in your Astro config. If undefined, this will return a URL generated from `localhost`.
+```astro
+---
+const path = Astro.site.pathname;
+---
+
+<h1>Welcome to {path}</h1>
+```
+
+### `Astro.resolve()`
+
+`Astro.resolve()` helps with creating URLs relative to the current Astro file, allowing you to reference files within your `src/` folder.
+
+Astro *does not* resolve relative links within HTML, such as images:
+
+```html
+<img src="../images/penguin.png" />
+```
+
+The above will be sent to the browser as-is and the browser will resolve it relative to the current __page__. If you want it to be resolved relative to the .astro file you are working in, use `Astro.resolve`:
+
+```astro
+<img src={Astro.resolve('../images/penguin.png')} />
+```
+
## `getStaticPaths()`
If a page uses dynamic params in the filename, that component will need to export a `getStaticPaths()` function.
r class='nohover-highlight'> Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com> 2023-08-18fix(polyfills): Use object shape for Stackblitz polyfill listGravatar Princesseuh 1-2/+2 2023-08-18fix: polyfill File using undici instead of node:buffer (#8139)Gravatar Erika 2-8/+9 * fix: polyfill File using undici instead of node:buffer * chore: changeset 2023-08-18[ci] release (beta) (#8073)create-astro@4.0.0-beta.1astro@3.0.0-beta.3@astrojs/vercel@4.0.0-beta.3@astrojs/telemetry@3.0.0-beta.2@astrojs/svelte@4.0.0-beta.1@astrojs/solid-js@3.0.0-beta.2@astrojs/react@3.0.0-beta.3@astrojs/mdx@1.0.0-beta.1@astrojs/cloudflare@7.0.0-beta.2Gravatar Houston (Bot) 63-117/+389 Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> 2023-08-18[ci] release (#8138)astro@2.10.11@astrojs/react@2.3.1Gravatar Houston (Bot) 44-80/+82 Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> 2023-08-18[ci] formatGravatar natemoo-re 1-1/+1 2023-08-18Fix 404 response leading to an infinite loop when there is no 404 page (#8136)Gravatar André Alves 2-1/+10 * fix: 404 response leads to infinite loop * chore: changeset --------- Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com> 2023-08-18fix(react): add missing export (#8137)Gravatar Nate Moore 2-1/+7 2023-08-18[ci] release (#8096)create-astro@3.2.2astro@2.10.10@astrojs/vercel@3.8.2@astrojs/svelte@3.1.1@astrojs/solid-js@2.2.1@astrojs/react@2.3.0Gravatar Houston (Bot) 63-197/+186 Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> 2023-08-18changeset(next): inlineStylesheets default switch is major (#8133)Gravatar Arsh 1-1/+1 2023-08-18feat: add polyfills for stackblitz (#8130)Gravatar Erika 7-6/+86 * feat: add polyfills for Stackblitz * chore: changeset