Sfoglia il codice sorgente

Merge https://github.com/gcushen/hugo-academic

Xℹ Ruoyao 5 anni fa
parent
commit
9f29b48d29

+ 14 - 14
assets/js/academic.js

@@ -355,7 +355,7 @@
     switch (newMode) {
       case 0:
         localStorage.setItem('dark_mode', '1');
-        isDarkTheme = 1;
+        isDarkTheme = true;
         console.info('User changed theme variation to Dark.');
         showActiveTheme(0);
         break;
@@ -363,10 +363,10 @@
         localStorage.setItem('dark_mode', '2');
         if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
           // The visitor prefers dark themes and switching to the dark variation is allowed by admin.
-          isDarkTheme = 1;
+          isDarkTheme = true;
         } else if (window.matchMedia('(prefers-color-scheme: light)').matches) {
           // The visitor prefers light themes and switching to the dark variation is allowed by admin.
-          isDarkTheme = 0;
+          isDarkTheme = false;
         } else {
           isDarkTheme = isSiteThemeDark;  // Use the site's default theme variation based on `light` in the theme file.
         }
@@ -375,7 +375,7 @@
         break;
       default:
         localStorage.setItem('dark_mode', '0');
-        isDarkTheme = 0;
+        isDarkTheme = false;
         console.info('User changed theme variation to Light.');
         showActiveTheme(2);
         break;
@@ -414,18 +414,18 @@
     let isDarkTheme;
     switch (currentThemeMode) {
       case 0:
-        isDarkTheme = 0;
+        isDarkTheme = false;
         break;
       case 1:
-        isDarkTheme = 1;
+        isDarkTheme = true;
         break;
       default:
         if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
           // The visitor prefers dark themes and switching to the dark variation is allowed by admin.
-          isDarkTheme = 1;
+          isDarkTheme = true;
         } else if (window.matchMedia('(prefers-color-scheme: light)').matches) {
           // The visitor prefers light themes and switching to the dark variation is allowed by admin.
-          isDarkTheme = 0;
+          isDarkTheme = false;
         } else {
           isDarkTheme = isSiteThemeDark;  // Use the site's default theme variation based on `light` in the theme file.
         }
@@ -437,7 +437,7 @@
   /**
    * Render theme variation (day or night).
    *
-   * @param {int} isDarkTheme - TODO: convert to boolean.
+   * @param {boolean} isDarkTheme
    * @param {boolean} init
    * @returns {undefined}
    */
@@ -452,12 +452,12 @@
     if (!init) {
       // If request to render light when light variation already rendered, return.
       // If request to render dark when dark variation already rendered, return.
-      if ((isDarkTheme === 0 && !$('body').hasClass('dark')) || (isDarkTheme === 1 && $('body').hasClass('dark'))) {
+      if ((isDarkTheme === false && !$('body').hasClass('dark')) || (isDarkTheme === true && $('body').hasClass('dark'))) {
         return;
       }
     }
 
-    if (isDarkTheme === 0) {
+    if (isDarkTheme === false) {
       if (!init) {
         // Only fade in the page when changing the theme variation.
         $('body').css({opacity: 0, visibility: 'visible'}).animate({opacity: 1}, 500);
@@ -475,7 +475,7 @@
           location.reload();
         }
       }
-    } else if (isDarkTheme === 1) {
+    } else if (isDarkTheme === true) {
       if (!init) {
         // Only fade in the page when changing the theme variation.
         $('body').css({opacity: 0, visibility: 'visible'}).animate({opacity: 1}, 500);
@@ -618,10 +618,10 @@
       if (currentThemeVariation === 2) {
         if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
           // The visitor prefers dark themes.
-          isDarkTheme = 1;
+          isDarkTheme = true;
         } else if (window.matchMedia('(prefers-color-scheme: light)').matches) {
           // The visitor prefers light themes.
-          isDarkTheme = 0;
+          isDarkTheme = false;
         } else {
           // The visitor does not have a day or night preference, so use the theme's default setting.
           isDarkTheme = isSiteThemeDark;

+ 6 - 0
assets/scss/academic/_card.scss

@@ -25,6 +25,12 @@
   border: 1px solid rgb(68, 71, 90);
 }
 
+/* In page listings, display the linked summaries as normal text except for the hover cursor. */
+a.summary-link {
+  color: unset;
+  text-decoration: none;
+}
+
 .card {
   margin-bottom: 1.5rem;
   overflow: hidden;

+ 1 - 1
assets/scss/academic/_dark.scss

@@ -39,7 +39,7 @@ body.dark,
 }
 
 .dark pre {
-  background-color: rgb(68, 71, 90);
+  /* Match `pre` bg color above. */
   border-color: rgb(68, 71, 90);
 }
 

+ 0 - 0
assets/scss/academic/_footer → assets/scss/academic/_footer.scss


+ 0 - 0
assets/scss/academic/icons.scss → assets/scss/academic/_icons.scss


+ 3 - 2
assets/scss/academic/_root.scss

@@ -168,12 +168,13 @@ pre,
 code {
   font-family: $sta-font-mono, monospace;
   color: #c7254e;
-  background-color: #f9f2f4;
+  /* Match bg of default highlight theme. */
+  background-color: rgb(248, 248, 248);
 }
 
 pre {
   margin: 0 0 1rem 0;
-  background-color: rgb(248, 248, 248); /* Match default highlight theme. */
+  /* Match bg of default highlight theme. */
   border-color: rgb(248, 248, 248);
   font-size: 0.7rem;
   border-radius: 4px;

+ 1 - 1
exampleSite/config/_default/params.toml

@@ -147,7 +147,7 @@ address_format = "en-us"
 ############################
 
 # Main menu alignment (l = left, c = center, r = right) and logo options.
-main_menu = {align = "l", show_logo = true}
+main_menu = {align = "l", show_logo = true, highlight_active_link = true, show_language = false}
 
 # Show estimated reading time for posts? (true/false)
 reading_time = true

+ 75 - 7
exampleSite/static/admin/config.yml

@@ -81,10 +81,10 @@ collections:
     create: true  # Allow users to create new documents in this collection
     fields:  # The fields each document in this collection have
       - {label: "Title", name: "title", widget: "string"}
-      - {label: "Subtitle", name: "subtitle", widget: "string"}
+      - {label: "Subtitle", name: "subtitle", widget: "string", required: false}
       - {label: "Body", name: "body", widget: "markdown"}
       - {label: "Publish this page on", name: "date", widget: "datetime"}
-      - {label: "Summary", name: "summary", widget: "markdown"}
+      - {label: "Summary", name: "summary", widget: "markdown", required: false}
       - label: "Draft"
         name: "draft"
         widget: "boolean"
@@ -125,6 +125,74 @@ collections:
           - {label: Description for screen readers, name: alt_text, widget: string, required: false}
           - {label: "Where's the focal point in the image? Smart, Center, TopLeft, Top, TopRight, Left, Right, BottomLeft, Bottom, BottomRight.", name: focal_point, widget: string, required: false, default: "Smart"}
           - {label: Thumbnail Only?, name: preview_only, widget: boolean, default: false}
+  - name: projects
+    label: Projects
+    label_singular: Project
+    folder: 'content/project'
+    path: '{{slug}}/index'
+    create: true  # Allow users to create new documents in this collection
+    fields:  # The fields each document in this collection have
+      - {label: "Title", name: "title", widget: "string"}
+      - {label: "Subtitle", name: "subtitle", widget: "string", required: false}
+      - {label: "Body", name: "body", widget: "markdown", required: false}
+      - {label: "Publish this page on", name: "date", widget: "datetime"}
+      - {label: "Summary", name: "summary", widget: "markdown", required: false}
+      - label: "Draft"
+        name: "draft"
+        widget: "boolean"
+        default: false
+      - label: "Featured"
+        name: "featured"
+        widget: "boolean"
+        default: false
+      - label: "Authors"
+        name: "authors"
+        required: false
+        widget: "list"
+      - label: "Tags"
+        name: "tags"
+        required: false
+        widget: "list"
+      - label: "Categories"
+        name: "categories"
+        required: false
+        widget: "list"
+      - {label: "External link (optional - replaces link to project page)", name: "external_link", widget: "string"}
+      - label: Links
+        name: links
+        required: false
+        widget: list
+        fields:
+          - {label: Link, name: url, widget: string}
+          - {label: Link text, name: name, widget: string, required: false}
+          - label: Icon pack
+            name: icon_pack
+            widget: select
+            multiple: false
+            required: false
+            options:
+              - {label: "None", value: ""}
+              - {label: "Solid", value: "fas"}
+              - {label: "Regular", value: "far"}
+              - {label: "Brand", value: "fab"}
+              - {label: "Academic", value: "ai"}
+          - {label: "Icon (see https://sourcethemes.com/academic/docs/page-builder/#icons)", name: icon, widget: string, required: false}
+      - label: "Featured Image"
+        name: "image"
+        required: false
+        widget: object
+        fields:
+          - label: "Upload an image named `featured.jpg/png`"
+            name: "filename"
+            widget: "image"
+            default: "featured"
+            media_library:
+              config:
+                multiple: false
+          - {label: Caption, name: caption, widget: string, required: false}
+          - {label: Description for screen readers, name: alt_text, widget: string, required: false}
+          - {label: "Where's the focal point in the image? Smart, Center, TopLeft, Top, TopRight, Left, Right, BottomLeft, Bottom, BottomRight.", name: focal_point, widget: string, required: false, default: "Smart"}
+          - {label: Thumbnail Only?, name: preview_only, widget: boolean, default: false}
   - name: talks
     label: Talks
     label_singular: Talk
@@ -201,7 +269,7 @@ collections:
           - {label: Description for screen readers, name: alt_text, widget: string, required: false}
           - {label: "Where's the focal point in the image? Smart, Center, TopLeft, Top, TopRight, Left, Right, BottomLeft, Bottom, BottomRight.", name: focal_point, widget: string, required: false, default: "Smart"}
           - {label: Thumbnail Only?, name: preview_only, widget: boolean, default: false}
-      - {label: "Details", name: "body", widget: "markdown"}
+      - {label: "Details", name: "body", widget: "markdown", required: false}
   - name: pages
     label: "Pages"
     files:
@@ -211,8 +279,8 @@ collections:
         fields:
           - {label: "Title", name: "title", widget: "string"}
           - {label: "Publish Date", name: "date", widget: "datetime"}
-          - {label: "Subtitle", name: "subtitle", widget: "string"}
-          - {label: "Summary", name: "summary", widget: "markdown"}
+          - {label: "Subtitle", name: "subtitle", widget: "string", required: false}
+          - {label: "Summary", name: "summary", widget: "markdown", required: false}
           - label: "Draft"
             name: "draft"
             required: false
@@ -225,8 +293,8 @@ collections:
         fields:
           - {label: "Title", name: "title", widget: "string"}
           - {label: "Publish Date", name: "date", widget: "datetime"}
-          - {label: "Subtitle", name: "subtitle", widget: "string"}
-          - {label: "Summary", name: "summary", widget: "markdown"}
+          - {label: "Subtitle", name: "subtitle", widget: "string", required: false}
+          - {label: "Summary", name: "summary", widget: "markdown", required: false}
           - label: "Draft"
             name: "draft"
             required: false

+ 3 - 1
layouts/_default/baseof.html

@@ -3,7 +3,9 @@
 <html lang="{{$language_code}}" {{ if in site.Data.i18n.rtl.rtl $language_code }}dir="rtl"{{end}}>
 
 {{ partial "site_head" . }}
-<body id="top" data-spy="scroll" data-offset="70" data-target="{{ if or .IsHome (eq .Type "widget_page") }}#navbar-main{{else}}#TableOfContents{{end}}" {{ if not (.Scratch.Get "light") }}class="dark"{{end}}>
+
+{{- $highlight_active_link := site.Params.main_menu.highlight_active_link | default true -}}
+<body id="top" data-spy="scroll" data-offset="70" data-target="{{ if or .IsHome (eq .Type "widget_page") | and $highlight_active_link }}#navbar-main{{else}}#TableOfContents{{end}}" {{ if not (.Scratch.Get "light") }}class="dark"{{end}}>
 
   {{ partial "search" . }}
 

+ 5 - 3
layouts/partials/li_card.html

@@ -54,9 +54,11 @@
   </h3>
 
   {{ with $summary }}
-  <div class="article-style">
-    <p>{{.}}</p>
-  </div>
+  <a href="{{ $item.RelPermalink }}" class="summary-link">
+    <div class="article-style">
+      <p>{{.}}</p>
+    </div>
+  </a>
   {{ end }}
 
   {{ if $show_buttons }}

+ 5 - 3
layouts/partials/li_compact.html

@@ -38,9 +38,11 @@
     </h3>
 
     {{ with $summary }}
-    <div class="article-style">
-      {{ . }}
-    </div>
+    <a href="{{ $item.RelPermalink }}" class="summary-link">
+      <div class="article-style">
+        {{.}}
+      </div>
+    </a>
     {{ end }}
 
     <div class="stream-meta article-metadata">

+ 8 - 3
layouts/partials/navbar.html

@@ -1,4 +1,6 @@
 {{ $current_page := . }}
+{{ $highlight_active_link := site.Params.main_menu.highlight_active_link | default true }}
+{{ $show_current_language := site.Params.main_menu.show_language | default false }}
 
 {{/* Get site logo. */}}
 {{ $show_logo := site.Params.main_menu.show_logo | default true }}
@@ -90,7 +92,7 @@
         {{ end }}
 
         <li class="nav-item">
-          <a class="nav-link {{if $is_link_in_current_path }} active{{end}}" href="{{.URL | relLangURL}}"{{ if and $is_widget_page $is_same_page }} data-target="{{$hash}}"{{ end }}{{ ($.Scratch.Get "target") | safeHTMLAttr }}>
+          <a class="nav-link {{if and $highlight_active_link $is_link_in_current_path }} active{{end}}" href="{{.URL | relLangURL}}"{{ if and $is_widget_page $is_same_page }} data-target="{{$hash}}"{{ end }}{{ ($.Scratch.Get "target") | safeHTMLAttr }}>
             {{- .Pre -}}<span>{{ .Name | safeHTML }}</span>{{- .Post -}}
           </a>
         </li>
@@ -151,8 +153,11 @@
 
       {{ if .IsTranslated }}
       <li class="nav-item dropdown i18n-dropdown">
-        <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown" aria-haspopup="true">
-          <i class="fas fa-globe mr-1" aria-hidden="true"></i><span class="d-none d-lg-inline">{{ index site.Data.i18n.languages .Lang }}</span>
+        <a href="#" class="nav-link {{ if $show_current_language }}dropdown-toggle{{end}}" data-toggle="dropdown" aria-haspopup="true">
+          <i class="fas fa-globe mr-1" aria-hidden="true"></i>
+          {{- if $show_current_language -}}
+            <span class="d-none d-lg-inline">{{ index site.Data.i18n.languages .Lang }}</span>
+          {{- end -}}
         </a>
         <div class="dropdown-menu">
           <div class="dropdown-item dropdown-item-active">