feat(manifest): add id and capabilities fields to notebook manifest
This commit is contained in:
parent
e5004fbf32
commit
00862f3aca
4 changed files with 34 additions and 29 deletions
|
|
@ -11,12 +11,17 @@ use crate::{fs_notebook::NotebookContext, pdel_parser::{preprocess::Expansion, P
|
|||
use super::{graph::BackLinksIndex, ids::Id, labels::LabelEntryIndex};
|
||||
|
||||
/// A user-config for the Notebook
|
||||
/// Result of the deserialization of a Notebook manifest.json file
|
||||
/// Result of the deserialization of a notebook.yaml file
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[fully_pub]
|
||||
struct Manifest {
|
||||
struct NotebookManifest {
|
||||
/// Notebook unique identifier (can be a UUID)
|
||||
id: String,
|
||||
/// Name or title of the notebook
|
||||
name: String,
|
||||
description: String
|
||||
description: String,
|
||||
/// List of enabled modules scopes
|
||||
capabilities: Vec<String>
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
|
|
@ -142,7 +147,7 @@ struct Notebook {
|
|||
files: Vec<SourceFile>,
|
||||
entries: Vec<EntryContainer>,
|
||||
// TODO: add a labels index
|
||||
manifest: Manifest,
|
||||
manifest: NotebookManifest,
|
||||
labels_index: LabelEntryIndex,
|
||||
backlinks: BackLinksIndex
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use git2::{Repository, Signature};
|
|||
use pathdiff::diff_paths;
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::{database::models::Manifest, indexer::{index_and_save, IndexingErr}};
|
||||
use crate::{database::models::NotebookManifest, indexer::{index_and_save, IndexingErr}};
|
||||
|
||||
use super::NotebookContext;
|
||||
|
||||
|
|
@ -22,7 +22,7 @@ pub enum InitErr {
|
|||
fn init_fs(desired_notebook: &NotebookContext) -> Result<(), io::Error> {
|
||||
std::fs::create_dir(desired_notebook.sources_path())?;
|
||||
std::fs::create_dir(desired_notebook.internals_path())?;
|
||||
let manifest = Manifest::empty();
|
||||
let manifest = NotebookManifest::empty();
|
||||
std::fs::write(
|
||||
desired_notebook.manifest_path(),
|
||||
serde_yaml::to_string(&manifest).expect("Encode empty manifest.")
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@ use std::path::Path;
|
|||
use std::io;
|
||||
use std::fs;
|
||||
use fully_pub::fully_pub;
|
||||
use crate::database::models::Manifest;
|
||||
use uuid::Uuid;
|
||||
use crate::database::models::NotebookManifest;
|
||||
|
||||
#[fully_pub]
|
||||
#[derive(Debug)]
|
||||
|
|
@ -16,31 +17,35 @@ enum ScanManifestErr {
|
|||
InvalidScheme
|
||||
}
|
||||
|
||||
impl Manifest {
|
||||
impl NotebookManifest {
|
||||
/// Scan a fanifest file
|
||||
pub fn from_path(manifest_path: &Path) -> Result<Manifest, ScanManifestErr> {
|
||||
pub fn from_path(manifest_path: &Path) -> Result<Self, ScanManifestErr> {
|
||||
if !manifest_path.exists() { return Err(ScanManifestErr::FileNotFound); }
|
||||
|
||||
let manifest_content = fs::read_to_string(manifest_path)
|
||||
.map_err(ScanManifestErr::CannotReadFile)?;
|
||||
|
||||
let data: Manifest = serde_yaml::from_str(&manifest_content)
|
||||
let data: Self = serde_yaml::from_str(&manifest_content)
|
||||
.map_err(ScanManifestErr::ParseError)?;
|
||||
|
||||
Ok(data)
|
||||
}
|
||||
|
||||
pub fn example() -> Manifest {
|
||||
Manifest {
|
||||
name: "Example Notebook".to_string(),
|
||||
description: "Notebook description".to_string(),
|
||||
pub fn example() -> Self {
|
||||
Self {
|
||||
id: "example".into(),
|
||||
name: "Example Notebook".into(),
|
||||
description: "Notebook description".into(),
|
||||
capabilities: vec!["calendar".into()]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn empty() -> Manifest {
|
||||
Manifest {
|
||||
name: "My super cool Notebook".to_string(),
|
||||
description: "This is a notebook description, feel free to change this.".to_string(),
|
||||
pub fn empty() -> NotebookManifest {
|
||||
Self {
|
||||
id: Uuid::new_v4().into(),
|
||||
name: "My super cool Notebook".into(),
|
||||
description: "This is a notebook description, feel free to change this.".into(),
|
||||
capabilities: vec![]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use crate::database::ids::Id;
|
||||
use crate::database::labels::LabelEntryIndex;
|
||||
use crate::database::graph::BackLinksIndex;
|
||||
use crate::database::models::{Entry, EntryContainer, Manifest, Notebook, SourceFile};
|
||||
use crate::database::models::{Entry, EntryContainer, NotebookManifest, Notebook, SourceFile};
|
||||
use crate::database::parse_extractor::{flatten_embedded_entries, ExtractErr};
|
||||
use crate::database::save::{save_db, SaveErr};
|
||||
use crate::pdel_parser::preprocess::{apply_expansions, preprocess_code, AdaptableRange, Expansion};
|
||||
|
|
@ -253,15 +253,10 @@ fn add_id_on_entry_code(expansions: &[Expansion], inp_file_code: &String, pout:
|
|||
fn index_notebook(context: &NotebookContext) -> Result<Notebook, IndexingErr>
|
||||
{
|
||||
// scan manifest file to get the name, description and others setting of the notebook
|
||||
let manifest = Manifest::from_path(&context.manifest_path())
|
||||
let manifest = NotebookManifest::from_path(&context.manifest_path())
|
||||
.map_err(IndexingErr::ManifestErr)?;
|
||||
|
||||
let index_res = match index_dir(&context.sources_path(), &context.sources_path()) {
|
||||
Ok(res) => res,
|
||||
Err(err) => {
|
||||
return Err(err)
|
||||
}
|
||||
};
|
||||
let index_res = index_dir(&context.sources_path(), &context.sources_path())?;
|
||||
|
||||
Notebook::build(
|
||||
manifest,
|
||||
|
|
@ -330,7 +325,7 @@ fn watch<P: AsRef<Path>>(path: P) -> notify::Result<()> {
|
|||
impl Notebook {
|
||||
/// build a notebook from components
|
||||
pub fn build(
|
||||
manifest: Manifest,
|
||||
manifest: NotebookManifest,
|
||||
files: Vec<SourceFile>,
|
||||
entries_containers: Vec<EntryContainer>
|
||||
) -> Result<Notebook, IndexingErr> {
|
||||
|
|
@ -370,11 +365,11 @@ impl Notebook {
|
|||
/// build virtual notebook from one single markdown string
|
||||
/// for now does not support macros
|
||||
pub fn build_virtual(
|
||||
manifest: Manifest,
|
||||
manifest: NotebookManifest,
|
||||
markdown_code: &str
|
||||
)-> Result<Notebook, IndexingErr> {
|
||||
let markdown_val = parse_markdown(markdown_code, 0).map_err(
|
||||
|_e| IndexingErr::ParseErr
|
||||
|e| IndexingErr::ParseErr(e)
|
||||
)?;
|
||||
let sf = SourceFile {
|
||||
id: Uuid::new_v4(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue