Adding few blank components that would make extending easier #1443
Replies: 5 comments 2 replies
-
|
Thanks for the suggestion @palmiak! Would you mind expanding a bit on any specific use cases, e.g. things you’d have loved to be able to slot into one of these four suggested locations? |
Beta Was this translation helpful? Give feedback.
-
|
The simplest thing - all weird marketing scripts, or adding some
functionality like OG:image (instead of overwriting head component).
czw., 1 lut 2024, 16:02 użytkownik Chris Swithinbank <
***@***.***> napisał:
… Thanks for the suggestion @palmiak <https://github.com/palmiak>!
Would you mind expanding a bit on any specific use cases, e.g. things
you’d have loved to be able to slot into one of these four suggested
locations?
—
Reply to this email directly, view it on GitHub
<#1443 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAR34OTR4V2ZQBHSHCE5LGDYROVAHAVCNFSM6AAAAABCT5QC7GVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4DGMZVHE3TA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
|
I would be interested in implementing those slots if you are interested.
Not pushing, but would love to help a bit 💪
Having real fun building our first docs using Starlight.
czw., 1 lut 2024, 19:13 użytkownik Chris Swithinbank <
***@***.***> napisał:
… Thanks — super helpful! I’m currently thinking about some head
improvements for things like the OG image, so it’s good to also hear about
similar needs elsewhere in the template.
—
Reply to this email directly, view it on GitHub
<#1443 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAR34OTIXL7QTM2GOHVGLVTYRPLLNAVCNFSM6AAAAABCT5QC7GVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4DGMZYGE3DM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
|
I like the idea about the middleware-like solution. For sure it would be
much more extensible from the plugin perspective.
Such tool could be quite universal and there could be more slots not only
header.
Footer (or right after the body open - don't remember for sure) slot might
be useful for noscript tag for GTM for example. So more slots might be
useful in some cases.
czw., 1 lut 2024, 20:03 użytkownik Chris Swithinbank <
***@***.***> napisał:
… Aww, that’s nice to hear!
Given these use cases are not really for UI but for scripts (because
injecting elements into these locations would break layout in every case I
think), I’m wondering if there’s a better API. I have an item on my to-do
list to write up a proposal for an injectHead() tool, kind of like a
“middleware” system for stuff that ends up in head, because in a way
component overrides feel like an odd fit here and make it harder for e.g.
multiple plugins to be involved. Now with your extra context, I can
consider if there are other needs for a similar API.
In theory there’s not much need these days for scripts at the end of the
page with <script defer> although I guess if you really want to delay
queuing something up for download it could help.
—
Reply to this email directly, view it on GitHub
<#1443 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAR34OQEK74ZJXXLTXPZ4N3YRPRIXAVCNFSM6AAAAABCT5QC7GVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4DGMZYGU2TS>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
|
Starting with Starlight 0.35.0, route data now include the Such data can be customized using a route data middleware. For example, to add some meta tags for Open Graph images, this would look like the following: // src/routeData.ts
import { defineRouteMiddleware } from "@astrojs/starlight/route-data";
export const onRequest = defineRouteMiddleware((context) => {
// Get the URL of the Open Graph image to use.
const ogImageUrl = new URL(`/og/my-og-image.png`, context.site);
// Get the array of all tags to include in the `<head>` of the current page.
const { head } = context.locals.starlightRoute;
// Add the `<meta/>` tags for the Open Graph images.
head.push({
tag: "meta",
attrs: { property: "og:image", content: ogImageUrl.href },
});
head.push({
tag: "meta",
attrs: { name: "twitter:image", content: ogImageUrl.href },
});
});You can of course use any of the route data properties in your middleware e.g. to compute a dynamic Open Graph image URL based on the current page's ID for example. As the most common use case suggested in this discussion was related to Open Graph images and it's getting quite old, I'll close this discussion and if we ever need to revisit some other solutions for different use cases, we can open a new discussion at that time. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
What version of
starlightare you using?0.17.2
What is your idea?
While adding things like OG is quite simple because we just have to override the
<Head />, it is more tricky to add something to the bottom of the page (right before ).Overall, I was thinking that maybe it would be a good idea to add a few blank components, that we can use just for extending.
For example:
They would be placed in the
Page.astro:As I mentioned - those components would be empty by default, so any overriding wouldn't break the core functionality.
Why is this feature necessary?
I think adding more components like this (and maybe it would be a good idea to add even more of them - not sure about this, only those 4 came to my mind as the most common ones) would make extending Starlight easier and safer because those components would serve more as "slots" to fill with some custom content.
Do you have examples of this feature in other projects?
The idea is a bit inspired by WordPress' hook system, where you create hooks that can be extended from other parts of the code.
https://www.hostinger.com/tutorials/what-are-wordpress-hooks/
Participation
Beta Was this translation helpful? Give feedback.
All reactions