Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(astro): add support for footer override #423

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

RonithManikonda
Copy link
Collaborator

adds support for overriding the footer component, similar to the TopBar override setup. Users can now customize footer content such as legal terms, contact info, and copyrights.

this change introduces Footer.astro and FooterWrapper.astro files to allow flexible slotting of footer items, improving customization for standalone tutorial deployments

close #323

adds support for overriding the footer component, similar to the TopBar override setup. Users can now customize footer content such as legal terms, contact info, and copyrights.

this change introduces `Footer.astro` and `FooterWrapper.astro` files to allow flexible slotting of footer items, improving customization for standalone tutorial deployments

close #323
Copy link

stackblitz bot commented Nov 21, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@AriPerkkio AriPerkkio changed the title feat(dev): add support for footer override feat(astro): add support for footer override Nov 22, 2024
Copy link

cloudflare-workers-and-pages bot commented Nov 22, 2024

Deploying tutorialkit-demo-page with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1c6f358
Status: ✅  Deploy successful!
Preview URL: https://84aefd36.tutorialkit-demo-page.pages.dev
Branch Preview URL: https://ronith-overriding-footer.tutorialkit-demo-page.pages.dev

View logs

Copy link
Member

@AriPerkkio AriPerkkio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @RonithManikonda, looks good so far! 💯

There are still couple of places we need to update:

  • Add the entrypoint here:

"exports": {
".": "./dist/index.js",
"./types": "./types.d.ts",
"./default-theme.css": "./dist/default/styles/variables.css",
"./default/pages/index.astro": "./dist/default/pages/index.astro",
"./default/pages/[...slug].astro": "./dist/default/pages/[...slug].astro",
"./default/components/TopBar.astro": "./dist/default/components/TopBar.astro",
"./default/components/HeadTags.astro": "./dist/default/components/HeadTags.astro",
"./package.json": "./package.json"
},

  • Mention the component here in the documentation:

  • Add types here:

declare module 'tutorialkit:override-components' {
const topBar: typeof import('./src/default/components/TopBar.astro').default;
const dialog: typeof import('@tutorialkit/react/dialog').default;
export { topBar as TopBar, dialog as Dialog };
}

  • Add component here:

/**
* A plugin that lets users override TutorialKit's components.
*
* The virtual module can be imported as:
*
* ```ts
* import { TopBar } from 'tutorialkit:override-components';
*
* <TopBar />
* ```
*
* User can override the components in `astro.config.ts`:
*
* ```ts
* export default defineConfig({
* integrations: [
* tutorialkit({
* components: {
* TopBar: './CustomTopBar.astro',
* Dialog: './CustomDialog.tsx',
* HeadTags: './CustomHeadLinks.astro',
* },
* }),
* ],
* });
* ```
*/
import type { VitePlugin } from '../types.js';
export interface OverrideComponentsOptions {
/**
* Component for overriding the top bar.
*
* This component has slots that are used to pass TutorialKit's default components:
* - `logo`: Logo of the application
* - `open-in-stackblitz-link`: Link for opening current lesson in StackBlitz
* - `theme-switch`: Switch for changing the theme
* - `login-button`: For StackBlitz Enterprise user, the login button
*
* Usage:
*
* ```jsx
* <slot name="logo" />
* <slot name="open-in-stackblitz-link" />
* <slot name="theme-switch" />
* <slot name="login-button" />
* ```
*/
TopBar?: string;
/**
* Component for overriding confirmation dialogs.
*
* This component has to be a React component and be the default export of that module.
* It will receive same props that `@tutorialkit/react/dialog` supports.
*/
Dialog?: string;
/**
* Component for overriding title, links and metadata in the `<head>` tag.
*
* This component has slots that are used to pass TutorialKit's default tags:
*
* - `title`: The page title
* - `links`: Links for the favicon, fonts and other assets
* - `meta`: Metadata and Open Graph tags
*
* ```jsx
* <slot name="title" />
* <slot name="links" />
* <slot name="meta" />
* ```
*/
HeadTags?: string;
}
interface Options {
components?: OverrideComponentsOptions;
defaultRoutes: boolean;
}
const virtualModuleId = 'tutorialkit:override-components';
const resolvedId = `\0${virtualModuleId}`;
export function overrideComponents({ components, defaultRoutes }: Options): VitePlugin {
return {
name: 'tutorialkit-override-components-plugin',
resolveId(id) {
if (id === virtualModuleId) {
return resolvedId;
}
return undefined;
},
async load(id) {
if (id === resolvedId) {
const topBar = components?.TopBar || resolveDefaultTopBar(defaultRoutes);
const headTags = components?.HeadTags || resolveDefaultHeadTags(defaultRoutes);
const dialog = components?.Dialog || '@tutorialkit/react/dialog';
return `
export { default as TopBar } from '${topBar}';
export { default as Dialog } from '${dialog}';
export { default as HeadTags } from '${headTags}';
`;
}
return undefined;
},
};
}
function resolveDefaultTopBar(defaultRoutes: boolean) {
if (defaultRoutes) {
return '@tutorialkit/astro/default/components/TopBar.astro';
}
// default `TopBar` is used from local file when `defaultRoutes` is disabled
return './src/components/TopBar.astro';
}
function resolveDefaultHeadTags(defaultRoutes: boolean) {
if (defaultRoutes) {
return '@tutorialkit/astro/default/components/HeadTags.astro';
}
// default `HeadTags` is used from local file when `defaultRoutes` is disabled
return './src/components/HeadTags.astro';
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Overriding the footer
2 participants