{ writers, ... }:
# TODO: figure if I can ever remove the hardcoded site value on the 
# last line of the config
writers.writeTOML "cliff.toml" {
  # https://git-cliff.org/docs/configuration

  changelog = {
    header = "";

    body = ''
      {%- macro remote_url() -%}
        https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}
      {%- endmacro -%}
      {% macro print_commit(commit) -%}
          - {% if commit.scope %}*({{ commit.scope }})* {% endif %}{% if commit.breaking %}[**breaking**] {% endif %}{{ commit.message | upper_first }} - ([{{ commit.id | truncate(length=7, end="") }}]({{ self::remote_url() }}/commit/{{ commit.id }}))
      {% endmacro -%}
      {% if version %}{% if previous.version %}## [{{ version | trim_start_matches(pat="v") }}]({{ self::remote_url() }}/compare/{{ previous.version }}..{{ version }}) - {{ timestamp | date(format="%Y-%m-%d") }}{% else %}## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }}{% endif %}{% else %}## [unreleased]{% endif %}
      {% for group, commits in commits | group_by(attribute="group") %}
          ### {{ group | striptags | trim | upper_first }}
          {% for commit in commits
          | filter(attribute="scope")
          | sort(attribute="scope") %}
              {{ self::print_commit(commit=commit) }}
          {%- endfor -%}
          {% raw %}{% endraw %}

          {%- for commit in commits %}
              {%- if not commit.scope -%}
                  {{ self::print_commit(commit=commit) }}
              {% endif -%}
          {% endfor -%}
      {% endfor %}
    '';
    footer = "";
    trim = true;
  };
  git = {
    # parse the commits based on https://www.conventionalcommits.org
    conventional_commits = true;
    # filter out the commits that are not conventional
    filter_unconventional = true;
    # process each line of a commit as an individual commit
    split_commits = true;
    # regex for parsing and grouping commits
    commit_parsers = [
      {
        message = "^feat";
        group = "<!-- 0 -->â›°ï¸�  Features";
      }
      {
        message = "^fix";
        group = "<!-- 1 -->ğŸ�› Bug Fixes";
      }
      {
        message = "^refactor";
        group = "<!-- 2 -->ğŸšœ Refactor";
      }
      {
        message = "^doc";
        group = "<!-- 3 -->ğŸ“š Documentation";
      }
      {
        message = "^style";
        group = "<!-- 4 -->ğŸ�¨ Styling";
      }
      {
        message = "^test";
        group = "<!-- 5 -->ğŸ§ª Testing";
      }
      {
        message = "^chore";
        skip = true;
      }
      {
        body = ".*security";
        group = "<!-- 6 -->ğŸ›¡ï¸� Security";
      }
      {
        body = ".*apps";
        group = "<!-- 7 -->ğŸ“± Apps";
      }
      {
        body = ".*checks";
        group = "<!-- 8 -->âœ… Checks";
      }
      {
        body = ".*common";
        group = "<!-- 9 -->âš« Common";
      }
      {
        body = ".*darwin";
        group = "<!-- 10 -->ğŸ�§ Darwin";
      }
      {
        body = ".*flake";
        group = "<!-- 11 -->â�„ï¸� Flake";
      }
      {
        body = ".*home-manager-modules";
        group = "<!-- 12 -->ğŸ�  HM";
      }
      {
        body = ".*hydra";
        group = "<!-- 13 -->ğŸ�� Hydra";
      }
      {
        body = ".*lib";
        group = "<!-- 14 -->ğŸ“š Lib";
      }
      {
        body = ".*linux";
        group = "<!-- 15 -->ğŸ˜˜ Linux";
      }
      {
        body = ".*modules";
        group = "<!-- 16 -->ğŸ§± Modules";
      }
      {
        body = ".*options";
        group = "<!-- 17 -->âš™ï¸� Options";
      }
      {
        body = ".*overlays";
        group = "<!-- 18 -->ğŸ�­ Overlays";
      }
      {
        body = ".*packages";
        group = "<!-- 19 -->ğŸ“¦ Packages";
      }
      {
        body = ".*secrets";
        group = "<!-- 20 -->ğŸ¤« Secrets";
      }
      {
        body = ".*shells";
        group = "<!-- 21 -->ğŸ�š Shells";
      }
      {
        body = ".*tooling";
        group = "<!-- 22 -->âš’ï¸� Tooling";
      }
      {
        body = ".*users";
        group = "<!-- 23 -->ğŸ™‹ Users";
      }
    ];
    # protect breaking changes from being skipped due to matching a skipping commit_parser
    protect_breaking_commits = false;
    # filter out the commits that are not matched by commit parsers
    filter_commits = true;
    # regex for matching git tags
    tag_pattern = ".*";
    # regex for skipping tags
    skip_tags = "beta|alpha";
    # regex for ignoring tags
    ignore_tags = "rc";
    # sort the tags topologically
    topo_order = false;
    # sort the commits inside sections by oldest/newest order
    sort_commits = "newest";
  };

  remote.github = {
    owner = "JayRovacsek";
    repo = "nix-config";
  };
}
