Provides functionalities for processing Jupyter Notebook files (.ipynb)
The module serves as the core of the ipynb2web conversion pipeline, handling various stages of content transformation and site structure generation. This includes converting notebooks to HTML, creating audio files from specified content, generating sitemaps for web navigation, and publishing processed files.
Functions exposed from node and cli into different web formats and managing related assets.
- Source:
Methods
(async, static) cli_nbs2html(FROMopt, directory, SAVETOopt, verboseopt) → {void}
Calls generate_sectionmap for each file in directory.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
FROM |
string |
<optional> |
'./' | The directory containing .ipynb files to process. |
directory |
string | A subdirectory to process within the FROM path. |
||
SAVETO |
string |
<optional> |
'./' | The directory where the processed files will be saved. |
verbose |
boolean |
<optional> |
false | If set to true, enables verbose logging for detailed information. |
- Source:
Throws:
-
Logs an error to the console if unable to process the specified directory and verbose is true.
- Type
- Error
Returns:
Does not return a value; the function is used for processing files in place.
- Type
- void
(async, static) createAudio(fromopt, toopt)
Checks YAML for audio
tag and creates the file
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
from |
string |
<optional> |
'./src/posts/' | The source directory containing content to be converted to audio. |
to |
string |
<optional> |
'./src/client/audio/' | The target directory where audio files will be saved. |
- Source:
(async, static) createSitemap(SAVETOopt, sitemapFileopt, verboseopt) → {void}
Appends each ipynb to sitemap.txt by calling processDirectory.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
SAVETO |
string |
<optional> |
'./src/posts/' | The directory to search for JSON map files. |
sitemapFile |
string |
<optional> |
'./sitemap.txt' | The file path where the sitemap will be saved. |
verbose |
boolean |
<optional> |
false | If set to true, enables verbose logging for detailed information. |
- Source:
Throws:
-
Logs an error to the console if there is a failure in writing the sitemap file and verbose is true.
- Type
- Error
Returns:
Does not return a value; processes and writes to the sitemap file directly.
- Type
- void
(async, static) generate_sectionmap(pages, FROM, directory, SAVETO, verboseopt) → {void}
Calls ipynb_publish on all files in the directory.
- Also creates section_map.json which is later used in createSitemap()
- It excludes specified metadata fields from section_map.json
- Skips _filename.ipynb files entirely and won't add meta.hide yaml's to the section_map.json
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pages |
Array.<string> | An array of page names to process. |
||
FROM |
string | The base directory containing .ipynb files. |
||
directory |
string | A subdirectory to process. |
||
SAVETO |
string | The directory where the section map will be saved. |
||
verbose |
boolean |
<optional> |
false | If set to true, enables verbose logging for detailed information. |
- Source:
Throws:
-
Logs an error to the console if there are issues creating the directory or writing the section map file and verbose is true.
- Type
- Error
Returns:
Does not return a value; processes files and creates a section map.
- Type
- void
(async, static) ipynb_publish(fullFilePath, saveDir, typeopt) → {Object}
Processes and publishes a Jupyter Notebook file, converting it to the specified format and saving it to a directory.
Optionally, extracts and saves Python code from the notebook.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
fullFilePath |
string | The full path to the Jupyter Notebook file, including the filename and extension. |
||
saveDir |
string | The directory where the processed file and any extracted Python code will be saved. |
||
type |
string |
<optional> |
'json' | The format for the output file ('json' is the default format). |
- Source:
Throws:
-
Logs an error to the console if there is a failure in writing the output file.
- Type
- Error
Returns:
The final processed data of the notebook.
- Type
- Object
(async, static) processDirectory(pages, directory, subdiropt, verboseopt) → {void}
Recursively searches for _map.json files created from [cli_nbs2html->generate_sectionmap and appends the mappings to sitemap.txt.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pages |
Array.<string> | An array to accumulate page URLs for the sitemap. |
||
directory |
string | The directory to process. |
||
subdir |
string |
<optional> |
'' | A subdirectory path to append to each URL in the sitemap. |
verbose |
boolean |
<optional> |
false | If set to true, enables verbose logging for detailed information. |
- Source:
Throws:
-
Logs an error to the console if unable to process a directory and verbose is true.
- Type
- Error
Returns:
Does not return a value; modifies the 'pages' array by reference.
- Type
- void