Module: Woods::Obsidian::VaultAssets

Defined in:
lib/woods/obsidian/vault_assets.rb

Overview

Generates the static-ish vault configuration files: the .obsidian/ settings Obsidian reads (app.json, types.json, graph.json) and the Units.base Obsidian Bases view.

Grounded in Steph Ango's published vault conventions and the official Obsidian docs:

  • app.json only governs links Obsidian generates; our authored [[path|alias]] links resolve regardless. We still set absolute-path wikilinks as a courtesy for the user's future edits.
  • We deliberately do NOT ship core-plugins.json — graph and Bases are enabled by default, and a partial plugin list could disable other defaults.
  • types.json types the properties so Bases columns sort numerically (pagerank/counts) and tags render as tags.
  • graph.json color groups apply to the global graph only (local-graph colors live in volatile workspace.json, which must not be shipped).

Constant Summary collapse

PALETTE =

Palette of 24-bit RGB ints assigned to type tags in sorted order so the graph coloring is deterministic across runs.

[
  0xE5_5A_5A, 0x5A_9B_E5, 0x5A_E5_8B, 0xE5_C8_5A, 0xB4_5A_E5,
  0x5A_E5_D6, 0xE5_8B_5A, 0x8B_E5_5A, 0xE5_5A_B4, 0x5A_6B_E5
].freeze
PROPERTY_TYPES =
{
  'id' => 'text', 'type' => 'text', 'file' => 'text', 'source_hash' => 'text',
  'pagerank' => 'number', 'dependency_count' => 'number', 'dependent_count' => 'number',
  'tags' => 'tags', 'aliases' => 'aliases'
}.freeze

Class Method Summary collapse

Class Method Details

.app_jsonString

Returns .obsidian/app.json.

Returns:

  • (String)

    .obsidian/app.json



40
41
42
43
44
45
46
# File 'lib/woods/obsidian/vault_assets.rb', line 40

def app_json
  pretty(
    'newLinkFormat' => 'absolute',
    'useMarkdownLinks' => false,
    'alwaysUpdateLinks' => true
  )
end

.graph_json(types) ⇒ String

Returns .obsidian/graph.json with per-type color groups.

Parameters:

  • types (Array<String>)

    singular unit types present in the vault

Returns:

  • (String)

    .obsidian/graph.json with per-type color groups



55
56
57
58
59
60
# File 'lib/woods/obsidian/vault_assets.rb', line 55

def graph_json(types)
  groups = Array(types).uniq.sort.each_with_index.map do |type, i|
    { 'query' => "tag:#woods/#{type}", 'color' => { 'a' => 1, 'rgb' => PALETTE[i % PALETTE.size] } }
  end
  pretty('colorGroups' => groups, 'showTags' => true, 'showAttachments' => false)
end

.pretty(hash) ⇒ Object



99
100
101
# File 'lib/woods/obsidian/vault_assets.rb', line 99

def pretty(hash)
  "#{JSON.pretty_generate(hash)}\n"
end

.types_jsonString

Returns .obsidian/types.json (property -> type registry).

Returns:

  • (String)

    .obsidian/types.json (property -> type registry)



49
50
51
# File 'lib/woods/obsidian/vault_assets.rb', line 49

def types_json
  pretty('types' => PROPERTY_TYPES)
end

.units_baseString

Returns Units.base — an Obsidian Bases view (YAML).

Returns:

  • (String)

    Units.base — an Obsidian Bases view (YAML)



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/woods/obsidian/vault_assets.rb', line 63

def units_base
  <<~YAML
    filters:
      and:
        - 'file.hasTag("woods/unit")'
    properties:
      type:
        displayName: Type
      pagerank:
        displayName: PageRank
      dependent_count:
        displayName: Used by
      dependency_count:
        displayName: Depends on
    views:
      - type: table
        name: All units
        groupBy: type
        order:
          - file.name
          - type
          - pagerank
          - dependent_count
          - dependency_count
      - type: table
        name: Hubs
        filters:
          and:
            - 'file.hasTag("woods/hub")'
        order:
          - file.name
          - dependent_count
          - pagerank
  YAML
end