charge/fs

Types

pub type Extension {
  MD
  MDX
  HTML
  JPG
  PNG
  JPEG
  WEBP
}

Constructors

  • MD
  • MDX
  • HTML
  • JPG
  • PNG
  • JPEG
  • WEBP

An absolute path based on the filesystem root

pub opaque type Path

An absolute path based on the site root

pub opaque type SitePath

Values

pub fn concat_site_path(a: SitePath, b: SitePath) -> SitePath

Just does a string concat of two site paths, dropping the leading slash of the second path

pub fn copy_site_dir(
  out: Path,
  from: Path,
  to: SitePath,
) -> Result(Nil, error.ChargeError)
pub fn cwd() -> Path
pub fn delete_dir(dir: Path) -> Result(Nil, error.ChargeError)
pub fn delete_dir_if_exists(
  dir: Path,
) -> Result(Nil, error.ChargeError)
pub fn ensure_dir(path: Path) -> Result(Nil, error.ChargeError)
pub fn ensure_relative_dir(
  rel: String,
) -> Result(Path, error.ChargeError)
pub fn ext(file: Path) -> Result(String, Nil)
pub fn file_name_only(file: Path) -> String
pub fn from_cwd(rel: String) -> Result(Path, error.ChargeError)
pub fn has_ext(file: Path, exts: List(Extension)) -> Bool
pub fn is_file(path: Path) -> Bool
pub fn ls_dir(at: Path) -> Result(List(Path), error.ChargeError)
pub fn parent(path: Path) -> Result(Path, error.ChargeError)
pub fn path_to_string(p: Path) -> String

Converts a path to string within the current working directory. This should only be used for printing data and not for working with paths

pub fn read_text_file(
  p: Path,
) -> Result(String, error.ChargeError)
pub fn resolve(
  dir: Path,
  relative: String,
) -> Result(Path, error.ChargeError)
pub fn site_path_from_string(
  site_path: String,
) -> Result(SitePath, error.ChargeError)
pub fn site_path_parts(path: SitePath) -> List(String)
pub fn site_path_starts_with(
  path: SitePath,
  prefix: SitePath,
) -> Bool
pub fn site_path_to_href(p: SitePath) -> #(String, String)
pub fn site_path_to_path(
  out_dir: Path,
  path: SitePath,
) -> Result(Path, error.ChargeError)
pub fn site_path_to_src(p: SitePath) -> #(String, String)
pub fn site_path_to_string(p: SitePath) -> String
pub fn to_abs_string(p: Path) -> String

Gets the absolute path as a string

pub fn to_site_path(
  dir: Path,
  p: Path,
  replace_ext: dict.Dict(Extension, Extension),
) -> SitePath
pub fn write_site_file(
  out_dir: Path,
  path: SitePath,
  content: String,
) -> Result(Nil, error.ChargeError)
Search Document