fix: Replace Figure with Image component in Notion importer
Browse files- Change mdx-converter to generate Image instead of Figure
- Update README examples to use Image
- Remove debug code from Dockerfile
- Figure component was removed, Image is the standard now
Dockerfile
CHANGED
|
@@ -45,13 +45,7 @@ RUN set -e; \
|
|
| 45 |
mkdir -p public/data; \
|
| 46 |
cp -a src/content/assets/data/. public/data/
|
| 47 |
|
| 48 |
-
# Build the application
|
| 49 |
-
RUN echo "🔍 Debug: Checking if article.mdx exists..." && \
|
| 50 |
-
ls -lh src/content/article.mdx && \
|
| 51 |
-
echo "🔍 Debug: Checking if Figure component exists..." && \
|
| 52 |
-
ls -lh src/components/Figure.astro && \
|
| 53 |
-
echo "🔍 Debug: First 20 lines of article.mdx:" && \
|
| 54 |
-
head -20 src/content/article.mdx
|
| 55 |
RUN npm run build
|
| 56 |
|
| 57 |
# Generate the PDF (light theme, full wait)
|
|
|
|
| 45 |
mkdir -p public/data; \
|
| 46 |
cp -a src/content/assets/data/. public/data/
|
| 47 |
|
| 48 |
+
# Build the application (with minimal placeholder content)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
RUN npm run build
|
| 50 |
|
| 51 |
# Generate the PDF (light theme, full wait)
|
app/scripts/notion-importer/README.md
CHANGED
|
@@ -73,7 +73,7 @@ notion-importer/
|
|
| 73 |
### 🎯 **Advanced Media Handling**
|
| 74 |
- **Local download**: Automatic download of all Notion media (images, files, PDFs)
|
| 75 |
- **Path transformation**: Smart path conversion for web accessibility
|
| 76 |
-
- **
|
| 77 |
- **Media organization**: Structured media storage by page ID
|
| 78 |
|
| 79 |
### 🧮 **Interactive Components**
|
|
@@ -121,7 +121,7 @@ published: "2024-01-15"
|
|
| 121 |
tableOfContentsAutoCollapse: true
|
| 122 |
---
|
| 123 |
|
| 124 |
-
import
|
| 125 |
import Note from '../components/Note.astro';
|
| 126 |
import gettingStartedImage from './media/getting-started/image1.png';
|
| 127 |
|
|
|
|
| 73 |
### 🎯 **Advanced Media Handling**
|
| 74 |
- **Local download**: Automatic download of all Notion media (images, files, PDFs)
|
| 75 |
- **Path transformation**: Smart path conversion for web accessibility
|
| 76 |
+
- **Image components**: Automatic conversion to Astro `Image` components with zoom/download
|
| 77 |
- **Media organization**: Structured media storage by page ID
|
| 78 |
|
| 79 |
### 🧮 **Interactive Components**
|
|
|
|
| 121 |
tableOfContentsAutoCollapse: true
|
| 122 |
---
|
| 123 |
|
| 124 |
+
import Image from '../components/Image.astro';
|
| 125 |
import Note from '../components/Note.astro';
|
| 126 |
import gettingStartedImage from './media/getting-started/image1.png';
|
| 127 |
|
app/scripts/notion-importer/mdx-converter.mjs
CHANGED
|
@@ -122,12 +122,12 @@ function addComponentImports(content) {
|
|
| 122 |
}
|
| 123 |
|
| 124 |
/**
|
| 125 |
-
* Transform Notion images to
|
| 126 |
* @param {string} content - MDX content
|
| 127 |
-
* @returns {string} - Content with
|
| 128 |
*/
|
| 129 |
function transformImages(content) {
|
| 130 |
-
console.log(' 🖼️ Transforming images to
|
| 131 |
|
| 132 |
let hasImages = false;
|
| 133 |
|
|
@@ -163,8 +163,8 @@ function transformImages(content) {
|
|
| 163 |
: cleaned;
|
| 164 |
};
|
| 165 |
|
| 166 |
-
// Create
|
| 167 |
-
const
|
| 168 |
const cleanSrc = cleanSrcPath(src);
|
| 169 |
|
| 170 |
// Skip PDF URLs and external URLs - they should remain as links only
|
|
@@ -177,7 +177,7 @@ function transformImages(content) {
|
|
| 177 |
|
| 178 |
const varName = generateImageVarName(cleanSrc);
|
| 179 |
imageImports.set(cleanSrc, varName);
|
| 180 |
-
usedComponents.add('
|
| 181 |
|
| 182 |
const props = [];
|
| 183 |
props.push(`src={${varName}}`);
|
|
@@ -187,30 +187,30 @@ function transformImages(content) {
|
|
| 187 |
if (alt) props.push(`alt="${alt}"`);
|
| 188 |
if (caption) props.push(`caption={'${caption}'}`);
|
| 189 |
|
| 190 |
-
return `<
|
| 191 |
};
|
| 192 |
|
| 193 |
// Transform markdown images: 
|
| 194 |
content = content.replace(/!\[([^\]]*)\]\(([^)]+)\)/g, (match, alt, src) => {
|
| 195 |
const cleanSrc = cleanSrcPath(src);
|
| 196 |
-
const cleanAlt = cleanAltText(alt || '
|
| 197 |
hasImages = true;
|
| 198 |
|
| 199 |
-
return
|
| 200 |
});
|
| 201 |
|
| 202 |
// Transform images with captions (Notion sometimes adds captions as separate text)
|
| 203 |
content = content.replace(/!\[([^\]]*)\]\(([^)]+)\)\s*\n\s*([^\n]+)/g, (match, alt, src, caption) => {
|
| 204 |
const cleanSrc = cleanSrcPath(src);
|
| 205 |
-
const cleanAlt = cleanAltText(alt || '
|
| 206 |
const cleanCap = cleanCaption(caption);
|
| 207 |
hasImages = true;
|
| 208 |
|
| 209 |
-
return
|
| 210 |
});
|
| 211 |
|
| 212 |
if (hasImages) {
|
| 213 |
-
console.log(' ✅
|
| 214 |
}
|
| 215 |
|
| 216 |
return content;
|
|
|
|
| 122 |
}
|
| 123 |
|
| 124 |
/**
|
| 125 |
+
* Transform Notion images to Image components
|
| 126 |
* @param {string} content - MDX content
|
| 127 |
+
* @returns {string} - Content with Image components
|
| 128 |
*/
|
| 129 |
function transformImages(content) {
|
| 130 |
+
console.log(' 🖼️ Transforming images to Image components...');
|
| 131 |
|
| 132 |
let hasImages = false;
|
| 133 |
|
|
|
|
| 163 |
: cleaned;
|
| 164 |
};
|
| 165 |
|
| 166 |
+
// Create Image component with import
|
| 167 |
+
const createImageComponent = (src, alt = '', caption = '') => {
|
| 168 |
const cleanSrc = cleanSrcPath(src);
|
| 169 |
|
| 170 |
// Skip PDF URLs and external URLs - they should remain as links only
|
|
|
|
| 177 |
|
| 178 |
const varName = generateImageVarName(cleanSrc);
|
| 179 |
imageImports.set(cleanSrc, varName);
|
| 180 |
+
usedComponents.add('Image');
|
| 181 |
|
| 182 |
const props = [];
|
| 183 |
props.push(`src={${varName}}`);
|
|
|
|
| 187 |
if (alt) props.push(`alt="${alt}"`);
|
| 188 |
if (caption) props.push(`caption={'${caption}'}`);
|
| 189 |
|
| 190 |
+
return `<Image\n ${props.join('\n ')}\n/>`;
|
| 191 |
};
|
| 192 |
|
| 193 |
// Transform markdown images: 
|
| 194 |
content = content.replace(/!\[([^\]]*)\]\(([^)]+)\)/g, (match, alt, src) => {
|
| 195 |
const cleanSrc = cleanSrcPath(src);
|
| 196 |
+
const cleanAlt = cleanAltText(alt || 'Image');
|
| 197 |
hasImages = true;
|
| 198 |
|
| 199 |
+
return createImageComponent(cleanSrc, cleanAlt);
|
| 200 |
});
|
| 201 |
|
| 202 |
// Transform images with captions (Notion sometimes adds captions as separate text)
|
| 203 |
content = content.replace(/!\[([^\]]*)\]\(([^)]+)\)\s*\n\s*([^\n]+)/g, (match, alt, src, caption) => {
|
| 204 |
const cleanSrc = cleanSrcPath(src);
|
| 205 |
+
const cleanAlt = cleanAltText(alt || 'Image');
|
| 206 |
const cleanCap = cleanCaption(caption);
|
| 207 |
hasImages = true;
|
| 208 |
|
| 209 |
+
return createImageComponent(cleanSrc, cleanAlt, cleanCap);
|
| 210 |
});
|
| 211 |
|
| 212 |
if (hasImages) {
|
| 213 |
+
console.log(' ✅ Image components with imports will be created');
|
| 214 |
}
|
| 215 |
|
| 216 |
return content;
|