浏览代码

feat: enable pages to be edited on GitHub

`edit_page` option can be added to `params.toml`. For example,
`edit_page = {repo_url = "https://github.com/gcushen/hugo-academic", editable = {docs = true}}`

Currently works for GitHub repos and pages using the `docs` layout.
George Cushen 6 年之前
父节点
当前提交
0810ee024f
共有 4 个文件被更改,包括 20 次插入5 次删除
  1. 7 3
      exampleSite/config/_default/params.toml
  2. 3 0
      i18n/en.yaml
  3. 1 1
      layouts/_default/baseof.html
  4. 9 1
      layouts/partials/docs_layout.html

+ 7 - 3
exampleSite/config/_default/params.toml

@@ -2,13 +2,13 @@
 # Documentation: https://sourcethemes.com/academic/
 
 # Color theme.
-#   Choose from `default`, `ocean`, `forest`, `dark`, `apogee`, `1950s`, `coffee`, `cupcake`, `strawberry`.
+#   Choose from `default`, `ocean`, `forest`, `dark`, `apogee`, `1950s`, `coffee`, `rose`, `strawberry`, `mr_robot`.
 color_theme = "default"
 # Enable users to switch between day and night mode?
 day_night = true
 
 # Font style.
-#   Choose from `default`, `classic`, or `playfair`.
+#   Choose from `default`, `classic`, `rose`, or `mr_robot`.
 font = "default"
 
 # Description for social sharing and search engines. If undefined, superuser role is used in place.
@@ -39,6 +39,10 @@ math = false
 #   Anonymize IP in Google Analytics (if enabled)
 privacy_pack = false
 
+# Enable visitors to edit pages?
+# `repo` defines the repository URL. `editable` defines which page types can be edited.
+edit_page = {repo_url = "https://github.com/gcushen/hugo-academic", editable = {docs = true}}
+
 # Date and time format (refer to https://sourcethemes.com/academic/docs/customization/#date-format )
 #   Examples: "Mon, Jan 2, 2006" or "2006-01-02"
 date_format = "Jan 2, 2006"
@@ -86,7 +90,7 @@ contact_links = [
 #   1: Google Maps
 #   2: OpenStreetMap (Mapnik)
 #   3: OpenStreetMap (Mapbox)
-map = 0
+map = 2
 map_api_key = ""
 latitude = "37.4275"
 longitude = "-122.1697"

+ 3 - 0
i18n/en.yaml

@@ -29,6 +29,9 @@
 - id: figure
   translation: "Figure %d:"
 
+- id: edit_page
+  translation: Edit this page
+
 # Buttons
 
 - id: btn_preprint

+ 1 - 1
layouts/_default/baseof.html

@@ -3,7 +3,7 @@
 
 {{ partial "site_head.html" . }}
 
-<body id="top" data-spy="scroll" data-target="{{ if or .IsHome (eq .Type "widget_page") }}#navbar-main{{else}}#TableOfContents{{end}}" data-offset="71" {{ if not (.Scratch.Get "light") }}class="dark"{{end}}>
+<body id="top" data-spy="scroll" data-target="{{ if or .IsHome (eq .Type "widget_page") }}#navbar-main{{else}}#TableOfContents{{end}}" data-offset="70" {{ if not (.Scratch.Get "light") }}class="dark"{{end}}>
 
   {{ partial "search" . }}
 

+ 9 - 1
layouts/partials/docs_layout.html

@@ -39,7 +39,15 @@
         </div>
 
         <div class="body-footer">
-          {{ i18n "last_updated" }} {{ $.Lastmod.Format site.Params.date_format }}
+          <p>{{ i18n "last_updated" }} {{ $.Lastmod.Format site.Params.date_format }}</p>
+
+          {{ if site.Params.edit_page.repo_url | and site.Params.edit_page.editable.docs | and (ne .Params.editable false) | or .Params.editable }}
+          <p class="edit-page">
+            <a href="{{site.Params.edit_page.repo_url}}/blob/master/content/{{.File.Path}}">
+              <i class="fas fa-pen pr-2"></i>{{ i18n "edit_page" | default "Edit this page" }}
+            </a>
+          </p>
+          {{ end }}
         </div>
 
       </article>