-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: api for r2 assets and fetch alt text from image captions (#59)
- **feat: API R2 assets** - **blog: update WordPress post with R2Image component for all four images** - **fix: remove signed URL logging** - **fix: replace all images in all blog posts with R2Image component** - **fix: set image caption as alt text in R2Image component** - **fix: placeholder alt text**
- Loading branch information
Showing
23 changed files
with
219 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,25 @@ | ||
import mdx from '@astrojs/mdx'; | ||
import sitemap from '@astrojs/sitemap'; | ||
import tailwind from "@astrojs/tailwind"; | ||
import tailwind from '@astrojs/tailwind'; | ||
import { defineConfig } from 'astro/config'; | ||
import { autoNewTabExternalLinks } from './src/autoNewTabExternalLinks'; | ||
|
||
import partytown from "@astrojs/partytown"; | ||
import partytown from '@astrojs/partytown'; | ||
|
||
// https://astro.build/config | ||
export default defineConfig({ | ||
site: 'https://www.arun.blog', | ||
integrations: [mdx(), sitemap(), tailwind(), partytown()], | ||
markdown: { | ||
extendDefaultPlugins: true, | ||
rehypePlugins: [[autoNewTabExternalLinks, { | ||
domain: 'localhost:4321' | ||
}]] | ||
} | ||
}); | ||
site: 'https://www.arun.blog', | ||
output: 'server', | ||
integrations: [mdx(), sitemap(), tailwind(), partytown()], | ||
markdown: { | ||
extendDefaultPlugins: true, | ||
rehypePlugins: [ | ||
[ | ||
autoNewTabExternalLinks, | ||
{ | ||
domain: 'localhost:4321', | ||
}, | ||
], | ||
], | ||
}, | ||
}); |
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,58 @@ | ||
--- | ||
interface Props { | ||
imageKey: string; | ||
alt: string; | ||
} | ||
const { imageKey, alt } = Astro.props; | ||
console.log('R2Image component rendering with props:', { imageKey, alt }); | ||
--- | ||
|
||
<img data-r2-key={imageKey} src='/placeholder.png' alt={alt} /> | ||
|
||
<script> | ||
async function refreshSignedUrls() { | ||
const images = document.querySelectorAll<HTMLImageElement>('img[data-r2-key]'); | ||
|
||
if (images.length === 0) { | ||
console.warn('No images found with data-r2-key attribute. DOM content:', document.body.innerHTML); | ||
} | ||
|
||
for (const img of images) { | ||
const imageKey = img.getAttribute('data-r2-key'); | ||
|
||
if (imageKey) { | ||
try { | ||
const response = await fetch(`/api/signedUrl?key=${encodeURIComponent(imageKey)}`, { | ||
headers: { | ||
Accept: 'application/json', | ||
}, | ||
}); | ||
|
||
if (!response.ok) { | ||
throw new Error(`HTTP error! status: ${response.status}`); | ||
} | ||
|
||
const data = await response.json(); | ||
|
||
if (data.url) { | ||
img.src = data.url; | ||
} else { | ||
console.error('No URL received in the response'); | ||
} | ||
} catch (error) { | ||
console.error('Failed to refresh signed URL:', error); | ||
} | ||
} else { | ||
console.warn('Image found without data-r2-key attribute'); | ||
} | ||
} | ||
} | ||
|
||
// Refresh URLs on page load | ||
refreshSignedUrls(); | ||
|
||
// Optionally, refresh URLs periodically | ||
setInterval(refreshSignedUrls, 50 * 60 * 1000); // Refresh every 50 minutes | ||
</script> |
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
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
Oops, something went wrong.