forked from openvinotoolkit/openvino_notebooks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request openvinotoolkit#1699 from yatarkan/yt/notebooks-li…
…braries-tags Enable ecosystem (libraries) tags in notebooks GitHub Pages app
- Loading branch information
Showing
8 changed files
with
251 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,10 @@ | |
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
|
||
img { | ||
padding-top: 0.25rem; | ||
} | ||
} | ||
} | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
112 changes: 112 additions & 0 deletions
112
selector/src/notebook-metadata/notebook-content-reader.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// @ts-check | ||
|
||
import { existsSync, readFileSync } from 'fs'; | ||
import { basename, dirname, join } from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
|
||
/** @typedef {import('../shared/notebook-metadata.ts').INotebookMetadata} INotebookMetadata */ | ||
/** | ||
* @typedef {{ | ||
* metadata: { openvino_notebooks?: Partial<INotebookMetadata> }; | ||
* cells: Array<{ cell_type: 'markdown' | 'code'; source: string[]; }> | ||
* }} INotebookJson | ||
*/ | ||
|
||
const CURRENT_DIR_PATH = dirname(fileURLToPath(import.meta.url)); | ||
|
||
export const NOTEBOOKS_DIRECTORY_PATH = join(CURRENT_DIR_PATH, '..', '..', '..', 'notebooks'); | ||
|
||
export class NotebookContentReader { | ||
/** | ||
* @param {string} notebookFilePath | ||
*/ | ||
constructor(notebookFilePath) { | ||
/** @protected */ | ||
this._notebookFilePath = notebookFilePath; | ||
|
||
this._checkFilesExist(); | ||
} | ||
|
||
/** | ||
* @private | ||
*/ | ||
_checkFilesExist() { | ||
if (!existsSync(this._absoluteNotebookPath)) { | ||
throw Error(`Notebook file "${this._notebookFilePath}" does not exists.`); | ||
} | ||
|
||
if (!existsSync(this._readmeFilePath)) { | ||
throw Error(`README.md file does not exists for notebook "${this._notebookFilePath}".`); | ||
} | ||
} | ||
|
||
/** | ||
* @private | ||
* @returns {string} | ||
*/ | ||
get _readmeFilePath() { | ||
return join(NOTEBOOKS_DIRECTORY_PATH, dirname(this._notebookFilePath), 'README.md'); | ||
} | ||
|
||
/** | ||
* @protected | ||
* @returns {string} | ||
*/ | ||
get _absoluteNotebookPath() { | ||
return join(NOTEBOOKS_DIRECTORY_PATH, this._notebookFilePath); | ||
} | ||
|
||
/** | ||
* @protected | ||
* @returns {string} | ||
*/ | ||
get _notebookFileName() { | ||
return basename(this._notebookFilePath); | ||
} | ||
|
||
/** | ||
* @protected | ||
* @returns {INotebookJson} | ||
*/ | ||
_getNotebookJson() { | ||
const notebookContent = readFileSync(this._absoluteNotebookPath, { encoding: 'utf8' }); | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return | ||
return JSON.parse(notebookContent); | ||
} | ||
|
||
/** | ||
* @protected | ||
* @returns {INotebookJson['cells']} | ||
*/ | ||
_getCodeCells() { | ||
return this._getNotebookJson().cells.filter(({ cell_type }) => cell_type === 'code'); | ||
} | ||
|
||
/** | ||
* @protected | ||
* @returns {string} | ||
*/ | ||
_getReadmeContent() { | ||
return readFileSync(this._readmeFilePath, { encoding: 'utf8' }); | ||
} | ||
|
||
/** | ||
* @protected | ||
* @template {keyof INotebookMetadata} K | ||
* @param {K} key | ||
* @returns {Partial<INotebookMetadata>[K] | null} | ||
*/ | ||
_getMetadataFromNotebookFile(key) { | ||
const { metadata } = this._getNotebookJson(); | ||
if (!metadata.openvino_notebooks) { | ||
console.warn(`No "openvino_notebooks" metadata found in notebook "${this._notebookFilePath}".`); | ||
return null; | ||
} | ||
const metadataPart = metadata.openvino_notebooks[key]; | ||
if (metadataPart === undefined) { | ||
console.warn(`"${key}" is not found in "openvino_notebooks" metadata for notebook "${this._notebookFilePath}".`); | ||
return null; | ||
} | ||
return metadataPart; | ||
} | ||
} |
Oops, something went wrong.