Module: Coradoc::RelativePath

Defined in:
lib/coradoc/relative_path.rb

Overview

Pure-function module for relative-path arithmetic across output keys.

Every SSG wrapper (VitePress, Hugo, Astro) needs to compute “how many directories up do I walk to reach the site root from this output?”. The answer is the segment count of the source output_key. Everything else (template, imports) is host-system-specific; this module owns only the one piece of arithmetic that is genuinely shared.

No state. No class. No knowledge of any specific SSG.

Examples:

Compute a VitePress import path

Coradoc::RelativePath.from("author/iso/ref/foo", to: ".vitepress/theme")
# => "../../../.vitepress/theme"

Class Method Summary collapse

Class Method Details

.from(output_key, to:) ⇒ String

Compute a relative path from an output_key to a site-root-relative target.

Parameters:

  • output_key (String, nil)

    site-relative key for the source page (e.g. “author/iso/ref/foo”). No leading slash, no extension.

  • to (String)

    destination path relative to the site root.

Returns:

  • (String)

    the composed relative path.



27
28
29
30
# File 'lib/coradoc/relative_path.rb', line 27

def from(output_key, to:)
  depth = output_key.to_s.count('/')
  ('../' * depth) + to.to_s
end