From 8113125633e29f8921b548673315f6dd83d3521e Mon Sep 17 00:00:00 2001 From: Daniele Guido Date: Sat, 26 Oct 2024 16:09:28 +0200 Subject: [PATCH] fix style for the notebooks --- src/components/NotebookViewer.css | 7 +++++++ src/components/NotebookViewer.tsx | 8 +++----- src/styles/global.css | 3 ++- updatenotebooks.js | 24 ++++++++++++++++++------ utils/ipynb.js | 4 ++++ 5 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 src/components/NotebookViewer.css diff --git a/src/components/NotebookViewer.css b/src/components/NotebookViewer.css new file mode 100644 index 0000000..953cdae --- /dev/null +++ b/src/components/NotebookViewer.css @@ -0,0 +1,7 @@ +.NotebookViewer h2 { + font-size: var(--font-size-h2); +} + +.NotebookViewer h3 { + font-size: var(--font-size-h3); +} diff --git a/src/components/NotebookViewer.tsx b/src/components/NotebookViewer.tsx index a230716..7f60b8e 100644 --- a/src/components/NotebookViewer.tsx +++ b/src/components/NotebookViewer.tsx @@ -6,6 +6,7 @@ import NotebookCard from "./NotebookCard" import AuthorCard from "./AuthorCard" import Alert from "./Alert" import { DateTime } from "luxon" +import "./NotebookViewer.css" export interface NotebookViewerProps { notebook: Notebook @@ -25,8 +26,6 @@ const splitTextWithCellInfo = ( const regex = /\{\/*\*\s*cell:(\d+)\s*cell_type:(\w+)\s*\*\/\}/g let match while ((match = regex.exec(text)) !== null) { - console.log(match) - debugger cells.push({ idx: match.index, l: match[0].length, @@ -35,8 +34,7 @@ const splitTextWithCellInfo = ( content: "", }) } - console.log("CELL", cells) - debugger + // now based on the indexes we can extract the content for (let i = 0; i < cells.length; i++) { const start = cells[i].idx + cells[i].l @@ -63,7 +61,7 @@ const NotebookViewer: React.FC = ({ const accessDateTime = DateTime.fromJSDate(accessTime) const excerpt = notebook.excerpt ?? "" return ( - +

diff --git a/src/styles/global.css b/src/styles/global.css index 0d97b66..36bd3d5 100644 --- a/src/styles/global.css +++ b/src/styles/global.css @@ -79,7 +79,8 @@ --bs-border-radius: 0.25rem; /* FONT SIZES */ --font-size-h1: var(--fs80px); - --font-size-h2: var(--fs40px); + --font-size-h2: var(--fs24px); + --font-size-h3: var(--fs18px); --font-size-h5: var(--fs18px); --font-small: var(--fs12px); diff --git a/updatenotebooks.js b/updatenotebooks.js index 9f1c252..f279a7c 100644 --- a/updatenotebooks.js +++ b/updatenotebooks.js @@ -52,7 +52,7 @@ if (notebookToUpdate) { const commit = await getLatestCommitFromUrl(url) if (!commit) { console.log( - "\x1b[33m⚠ skip\x1b[0m, no commit found? Please double check tuhe url." + "\x1b[33m⚠ skip\x1b[0m, no commit found? Please double check tuhe url.", ) continue } @@ -61,7 +61,7 @@ if (notebookToUpdate) { // if the sha is the same as the one in the frontmatter, we skip if (!process.env.FORCE_UPDATE && frontmatter.sha === commit.sha) { console.log( - "\x1b[33m⚠ skip\x1b[0m, sha is the same as the one in the frontmatter" + "\x1b[33m⚠ skip\x1b[0m, sha is the same as the one in the frontmatter", ) continue } @@ -75,13 +75,17 @@ if (notebookToUpdate) { // save the content to the notebook file if (!ipynb) { console.log( - "\x1b[33m⚠ skip\x1b[0m, no ipynb found? Please double check the url." + "\x1b[33m⚠ skip\x1b[0m, no ipynb found? Please double check the url.", ) continue } console.log("✓ ipynb", ipynb.cells.length, "cells") - const { title, cellIdx } = getTitleFromIpynb(ipynb.cells) + const { + title, + source: sourceWithoutTitle, + cellIdx, + } = getTitleFromIpynb(ipynb.cells) if (!title) { console.log("⚠ title? no heading found in ipynb") continue @@ -89,11 +93,19 @@ if (notebookToUpdate) { console.log("✓ title:", `\x1b[33m${title}\x1b[0m`) const { content: contentMdx, links } = extractMdFromIpynbCells( ipynb.metadata.kernelspec, - ipynb.cells.filter((_d, i) => i !== cellIdx) + ipynb.cells.map((_d, i) => { + if (i !== cellIdx) { + return _d + } + return { + ..._d, + source: sourceWithoutTitle, + } + }), ) const googleColabUrl = `https://colab.research.google.com/${url.replace( /https:\/\/.*?github.com/, - "github" + "github", )}` // get current yaml from frontùatter const newFrontmatter = { diff --git a/utils/ipynb.js b/utils/ipynb.js index cd88e08..1c2bda9 100644 --- a/utils/ipynb.js +++ b/utils/ipynb.js @@ -44,6 +44,9 @@ export const getTitleFromIpynb = (cells) => { const cellWithH1idx = cells.findIndex((cell) => { if (cell.cell_type !== "markdown") return false if (Array.isArray(cell.source)) { + if (cell.source.length === 0) { + return false + } return cell.source[0].trim().startsWith("# ") } return cell.source.startsWith("# ") @@ -57,6 +60,7 @@ export const getTitleFromIpynb = (cells) => { if (Array.isArray(cellWithH1.source)) { return { title: cellWithH1.source[0].trim().replace(/#/g, "").trim(), + source: cellWithH1.source.slice(1), cellIdx: cellWithH1idx, } } else {