         (format "%s\n%s%s" beginning-of-content toc-string rest-of-content)
       content)))
 
+(defun spacemacs//toc-org-unhrefify-toc ()
+  "Make TOC classical org-mode TOC."
+  (let ((toc-org-hrefify-default "org"))
+    (toc-org-insert-toc)))
+
+(defun spacemacs//org-heading-annotate-custom-id ()
+  "Annotate headings with the indexes that GitHub uses for linking.
+`org-html-publish-to-html' will use them instead of the default #orgheadline{N}.
+This way the GitHub links and the http://spacemacs.org/ links will be compatible."
+  (progn (goto-char (point-min))
+         (goto-char (point-min))
+         (while (re-search-forward "^[\\*]+\s\\(.*\\).*$" nil t)
+           (let ((heading (match-string 1)))
+             (progn (move-end-of-line nil)
+                    (open-line 1)
+                    (next-line 1)
+                    (insert (format (concat "  :PROPERTIES:\n"
+                                            "  :CUSTOM_ID: %s\n"
+                                            "  :END:\n")
+                                    (substring (toc-org-hrefify-gh
+                                                (replace-regexp-in-string
+                                                 toc-org-tags-regexp
+                                                 ""
+                                                 heading))
+                                               ;; Remove # prefix added by `toc-org-hrefify-gh'.
+                                               1))))))))
+
+(defun spacemacs//reroot-links ()
+  "Find the links that start with https://github.com/syl20bnr/spacemacs/blob/
+and end with .org{#an-optional-heading-link} (i.e the links between the local org files).
+Change their root to http://spacemacs.org/ so the links will point at files located on the site.
+For the file to file links to work properly the exported org files should be processed with
+the `spacemacs//org-heading-annotate-custom-id' function."
+  (let ((git-url-root-regexp
+         (concat "\\[\\[[\\s]*\\(https\\:\\/\\/github\\.com\\/syl20bnr"
+                 "\\/spacemacs\\/blob\\/[^/]+\\/\\)[^]]+\\(\\.org\\).*$"))
+        (site-url "http://spacemacs.org/")
+        (site-doc-postf ".html"))
+    (progn (goto-char (point-min))
+           (while (re-search-forward git-url-root-regexp nil t)
+             (progn (replace-match site-url nil t nil 1)
+                    (replace-match site-doc-postf nil t nil 2))))))
+
 (defun spacemacs//add-org-meta-readtheorg-css (filename)
   (let* ((head-css-extra-readtheorg-head (concat
                                           "#+HTML_HEAD_EXTRA:"

           (goto-char (point-min))
           (if (search-forward "#+TITLE:" nil t nil)
               (beginning-of-line 2)
             (error "Can't find #+TITLE:"))
           (insert (concat head-css-extra-readtheorg-head
                           (f-relative user-emacs-directory
                                       (file-name-directory filename))
                           head-css-extra-readtheorg-tail)))))

(defun spacemacs//pub-doc-html-advice (origfunc &rest args)
  (save-current-buffer
    (save-excursion
      (let* ((filename (car (nthcdr 1 args)))

(require 's)
(require 'dash)
(require 'f)
(require 'toc-org)
(require 'org-id)

(defvar spacemacs--category-names
  '(("config-files" . "Configuration files")
