Pena

Nestero
Bismillahirrahmanirrahim

Pena

Pena adalah aplikasi desktop sederhana yang dibangun menggunakan Tauri, untuk menulis konten website yang dibangun menggunakan hugo, seperti catatan ini, catatan ini ditulis menggunakan Pena.

Cara Kerja

Cara kerja Pena sangan sederhana, pena akan membaca isi direktori content, untuk melist semua section dan konten yang ada, kemudian memparsing file konten .md, untuk saat ini pena hanya support format yaml untuk front matternya, sangat simpel kan cara kerjanya 😁. Berikut beberapa potongan kode dari pena :

List Section

pub fn list_section(path: &str) -> Result<Vec<String>, String> {
    let mut section = Vec::new();

    let mut section_path = PathBuf::from(path);
    section_path.push("content");
    
    let entries = fs::read_dir(&section_path).map_err(|e| format!("Gagal Membaca direktori {}: {} ", section_path.display(), e))?;

    for entry in entries {
        if let Ok(entry) = entry {
            let path = entry.path();
            
            if path.is_dir() {
                if let Some(section_name) = path.file_name() {
                    section.push(section_name.to_string_lossy().to_string());
                }
            }
        }
    }

    Ok(section)
}

List Konten .md

pub fn list_konten(hugo_root_path: &str, section: &str) -> Result<Vec<String>, String> {

    let mut path = PathBuf::from(hugo_root_path);
    path.push("content");
    path.push(section);

    let mut files = Vec::new();
    let entries = fs::read_dir(&path).map_err(|e| format!("Gagal Membaca direktori {}: {} ", path.display(), e))?;

    for entry in entries {
        if let Ok(entry) = entry {
            let path = entry.path();
            if path.is_file() {
                if let Some(ext) = path.extension() {
                    if ext == "md" {
                        if let Some(filename) = path.file_name() {
                            files.push(filename.to_string_lossy().to_string());
                        }
                    }
                }
            }
        }
    }

    Ok(files)
}

Parse Markdown

pub fn baca_konten(hugo_root_path: &str, section: &str, file_name: &str) -> Result<KontenMarkdown, String> {
    let filepath = build_content_path(hugo_root_path, section, file_name);

    let content = fs::read_to_string(&filepath)
        .map_err(|e| format!("Gagal membaca file {}: {}", filepath.display(), e))?;

    // parser YAML
    let matter = Matter::<YAML>::new();

    let result: ParsedEntity<FrontMatter> = matter.parse(&content)
        .map_err(|e| format!("Gagal mem-parsing markdown : {}", e))?;

    let front_matter = result.data
        .ok_or_else(|| "File tidak memiliki front matter.".to_string())?;

    Ok(KontenMarkdown {
        front_matter,
        konten: result.content,
    })

}

Front Matter

pub struct FrontMatter {
    pub title: String,
    pub slug: Option<String>,
    pub date: String,
    pub draft: bool,
    pub author: Option<String>,
    pub categories: Vec<String>,
    pub tags: Vec<String>,
    pub referensi: Option<Vec<String>>,
    pub thumb: Option<String>
}

Fitur

Untuk saat ini pena hanya memiliki fitur standar antara lain :

  • [+] Tambah Konten
  • [+] Editor support fitur markdown
  • [+] Hapus Konten
  • [+] List Konten berdasarkan Section
  • [+] Pencarian Konten
  • [+] Push Git

Screenshot

Pena Pena

Sesungguhnya yang menyebabkan ilmu hilang adalah lupa dan tidak mengulanginya.

"Sesungguhnya yang menyebabkan ilmu hilang adalah lupa dan tidak mengulanginya."

Imam Az-Zuhri rahimahullah

Tags:

Referensi:

Catatan Terkait:

NESTECH ID

Copyright 2025. All rights reserved.