;;; sidenotes.el --- Sidenote / no-sidenotes helpers -*- lexical-binding: t; -*-

;;; Commentary:
;; Predicates for deciding whether a page should render with sidenotes.
;; Loaded by build-site.el via (require 'sidenotes).
;;
;; NOTE: Do NOT define `site-root' here.  build-site.el owns that definition.

;;; Code:

(defun z/no-sidenotes-file-p (file)
  "Return non-nil if FILE should be rendered without sidenotes.

A file suppresses sidenotes when any of the following is true:
  - It has a #+NO_SIDENOTES: keyword with a non-empty value.
  - Its FILETAGS contain :NO_SIDENOTES: or :KANBAN:.
  - Any top-level heading contains the word \"KANBAN\" (case-insensitive)."
  (when (file-exists-p file)
    (with-temp-buffer
      (insert-file-contents file)
      (org-mode)
      (let* ((case-fold-search t)
             (keywords (org-collect-keywords '("NO_SIDENOTES" "FILETAGS")))
             (flag     (cadr (assoc "NO_SIDENOTES" keywords)))
             (filetags (cadr (assoc "FILETAGS"     keywords))))
        (or
         ;; Explicit keyword present with any non-whitespace value
         (and flag (string-match-p "\\S-" flag))
         ;; Tag-based suppression
         (and filetags
              (string-match-p ":\\(NO_SIDENOTES\\|KANBAN\\):"
                              (concat ":" filetags ":")))
         ;; Heading-based suppression
         (save-excursion
           (goto-char (point-min))
           (re-search-forward "^\\*+ .*KANBAN.*" nil t)))))))

(provide 'sidenotes)

;;; sidenotes.el ends here