Skip to content

Commit

Permalink
fix style for the notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleguido committed Oct 26, 2024
1 parent c2013d0 commit 8113125
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 12 deletions.
7 changes: 7 additions & 0 deletions src/components/NotebookViewer.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.NotebookViewer h2 {
font-size: var(--font-size-h2);
}

.NotebookViewer h3 {
font-size: var(--font-size-h3);
}
8 changes: 3 additions & 5 deletions src/components/NotebookViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -63,7 +61,7 @@ const NotebookViewer: React.FC<NotebookViewerProps> = ({
const accessDateTime = DateTime.fromJSDate(accessTime)
const excerpt = notebook.excerpt ?? ""
return (
<Container>
<Container className="NotebookViewer">
<Row className="my-3">
<h1 dangerouslySetInnerHTML={{ __html: notebook.title }} />
</Row>
Expand Down
3 changes: 2 additions & 1 deletion src/styles/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
24 changes: 18 additions & 6 deletions updatenotebooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -75,25 +75,37 @@ 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
}
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 = {
Expand Down
4 changes: 4 additions & 0 deletions utils/ipynb.js
Original file line number Diff line number Diff line change
Expand Up @@ -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("# ")
Expand All @@ -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 {
Expand Down

0 comments on commit 8113125

Please sign in to comment.