server.js 780 B

12345678910111213141516171819202122232425
  1. function check(Component) {
  2. return Component['render'] && Component['$$render'];
  3. }
  4. function needsHydration(metadata) {
  5. // Adjust how this is hydrated only when the version of Astro supports `astroStaticSlot`
  6. return metadata.astroStaticSlot ? !!metadata.hydrate : true;
  7. }
  8. async function renderToStaticMarkup(Component, props, slotted, metadata) {
  9. const tagName = needsHydration(metadata) ? 'astro-slot' : 'astro-static-slot';
  10. const slots = {};
  11. for (const [key, value] of Object.entries(slotted)) {
  12. slots[key] = () =>
  13. `<${tagName}${key === 'default' ? '' : ` name="${key}"`}>${value}</${tagName}>`;
  14. }
  15. const { html } = Component.render(props, { $$slots: slots });
  16. return { html };
  17. }
  18. export default {
  19. check,
  20. renderToStaticMarkup,
  21. supportsAstroStaticSlot: true,
  22. };