Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion bin/ensure-ai-cookbook.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ const { existsSync, mkdirSync, writeFileSync } = require('fs');
const path = require('path');

const WORKSPACE_ROOT = path.resolve(__dirname, '..');
const OUTPUT_DIR = path.join(WORKSPACE_ROOT, process.env.AI_COOKBOOK_OUTPUT_DIR ?? 'ai-cookbook');
const outputDirFromEnv = process.env.AI_COOKBOOK_OUTPUT_DIR ?? 'ai-cookbook';
const OUTPUT_DIR = path.resolve(WORKSPACE_ROOT, outputDirFromEnv);

if (OUTPUT_DIR !== WORKSPACE_ROOT && !OUTPUT_DIR.startsWith(`${WORKSPACE_ROOT}${path.sep}`)) {
throw new Error('[ensure-ai-cookbook] AI_COOKBOOK_OUTPUT_DIR must resolve within the repository root');
}

const PLACEHOLDER_PATH = path.join(OUTPUT_DIR, 'recipes-not-synced.mdx');

// Ensure ai-cookbook directory exists with a placeholder file.
Expand Down
26 changes: 25 additions & 1 deletion src/components/elements/CallToAction.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
import React from 'react';
import styles from './call-to-action.module.css';

const getSafeHref = (href) => {
if (typeof href !== 'string') {
return '#';
}

const value = href.trim();

if (!value || value.startsWith('/') || value.startsWith('#') || value.startsWith('?')) {
return value || '#';
}

const lowerValue = value.toLowerCase();

if (
lowerValue.startsWith('http://') ||
lowerValue.startsWith('https://') ||
lowerValue.startsWith('mailto:')
) {
return value;
}

return '#';
};

export const CallToAction = ({ href, children }) => {
return (
<a href={href} className={styles.cta}>
<a href={getSafeHref(href)} className={styles.cta}>
<div className={styles.content}>
{children}
</div>
Expand Down