Skip to content

Instantly share code, notes, and snippets.

@Zund4m0n
Last active December 11, 2024 19:21
Show Gist options
  • Save Zund4m0n/dbc2a76f3bb2ca624ecfdcd26f1be0a4 to your computer and use it in GitHub Desktop.
Save Zund4m0n/dbc2a76f3bb2ca624ecfdcd26f1be0a4 to your computer and use it in GitHub Desktop.

How to start Hugo site

Clone Template and Setup Git

❯ git clone https://github.com/adityatelange/hugo-PaperMod mysite --depth=1
Cloning into 'mysite'...
remote: Enumerating objects: 139, done.
remote: Counting objects: 100% (139/139), done.
remote: Compressing objects: 100% (100/100), done.
remote: Total 139 (delta 38), reused 126 (delta 34), pack-reused 0 (from 0)
Receiving objects: 100% (139/139), 249.22 KiB | 153.00 KiB/s, done.
Resolving deltas: 100% (38/38), done.

❯ git init
Reinitialized existing Git repository in../mysite/.git/

❯ git remote add origin "https://oauth2:$PAT@github.com/<username>/papermod-demo"
fatal: not a git repository (or any parent up to mount point /mnt)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).

❯ git init
Initialized empty Git repository in ../mysite/.git/

❯ git remote add origin "https://oauth2:$PAT@github.com/<username>/papermod-demo"

❯ git add .

❯ git commit -m 'first commit'

Then create repo at website. Named papermod-demo

❯ git push origin main

If you miss type PAT, retry as below:

set PAT ghp_*****************************

❯ git remote set-url origin "https://oauth2:$PAT@github.com/<username>/papermod-demo"

❯ git push origin main

Build

❯ sed -i 's/adityatelange/<username>/g' theme.toml

❯ sed -i 's/hugo-PaperMod/<reponame>/g' theme.toml

❯ hugo

Deploy

❯ git add -A

❯ git commit -m 'builded'
git [main 8a35a5b] builded
p 12 files changed, 834 insertions(+), 3 deletions(-)
 create mode 100644 .hugo_build.lock
 create mode 100644 public/404.html
 create mode 100644 public/assets/css/stylesheet.fc220c15db4aef0318bbf30adc45d33d4d7c88deff3238b23eb255afdc472ca6.css
 create mode 100644 public/categories/index.html
 create mode 100644 public/categories/index.xml
 create mode 100644 public/index.html
 create mode 100644 public/index.xml
 create mode 100644 public/page/1/index.html
 create mode 100644 public/sitemap.xml
 create mode 100644 public/tags/index.html
 create mode 100644 public/tags/index.xml

❯ git push origin main
Enumerating objects: 23, done.
Counting objects: 100% (23/23), done.
Delta compression using up to 2 threads
Compressing objects: 100% (17/17), done.
Writing objects: 100% (21/21), 8.86 KiB | 76.00 KiB/s, done.
Total 21 (delta 7), reused 0 (delta 0), pack-reused 0 (from 0)
remote: Resolving deltas: 100% (7/7), completed with 2 local objects.
To https://github.com/username/papermod-demo
   36f1a80..8a35a5b  main -> main

Publish

First you must public your repository, at GitHub settings page:

Change:
  - Source: Github Actions
  - Branch: `/docs`

Next, you should append github-actions-workflow, then save as .github/workflow/hugo.yaml,

# Step 6 from https://gohugo.io/hosting-and-deployment/hosting-on-github
mkdir -p .github/workflow/
pbpaste > .github/workflows/hugo.yaml

git add -A
git commit -m 'add workflow deploy'
git push origin main

Now you can access your website: https://username.github.io/papermod-demo !

Post

So let's post your first article

Add markdown doc in /contents/*

mkdir contents
code contents/getting-started-hugo-site.md

Article like below:

---
title: "Archive"
layout: "archives"
url: "/archives/"
summary: archives
---

# Getting started Hugo website!
...


Then build and deploy:
```bash
hugo build

git add -A
git commit -m 'first post'
git push origin main

Customize website

For more information about customization the theme, see here and here.

@Zund4m0n
Copy link
Author

Zund4m0n commented Oct 7, 2024

@Zund4m0n
Copy link
Author

Zund4m0n commented Oct 7, 2024

@Zund4m0n
Copy link
Author

Zund4m0n commented Oct 7, 2024

This tutorial use theme as Fixed theme. It makes repository clear, but cannot change theme later.

@morisono
Copy link

morisono commented Oct 11, 2024

add

contentDir = ‘content/ja/posts’

then

ghq get https://github.com/adityatelange/hugo-PaperMod/tree/exampleSite my-papermod
rsync -auvz hugo-PaperMod/ ../tmp/my-papermod

hugo new site . --force
hugo new posts/ja/01.01_first-post.md  # Alternative you can use snippet

rm -rf .git
git init 
git remot add ...

@morisono
Copy link

@morisono
Copy link

@morisono
Copy link

@morisono
Copy link

morisono commented Oct 12, 2024

印刷・テキストや画像の選択を禁じる

code assets/css/extended/secure.scss
p, img, .protect{
  pointer-events:none;
  -webkit-touch-callout:none;
  -webkit-user-select:none;
  -moz-touch-callout:none;
  -moz-user-select:none;
  touch-callout:none;
  user-select:none;
}

@media print {
  body {
    visibility: hidden;
  }
}
<body onCopy="return false;">サイト全体をコピーさせたくない。</body>
<body onContextmenu="return false;"></body>

<script>
  document.body.oncopy = function(event) { 
    event.preventDefault(); 
  }
</script>

@morisono
Copy link

@morisono
Copy link

@morisono
Copy link

git submodule add https://github.com/alex-shpak/hugo-book themes/hugo-book
hugo server --minify --theme hugo-book

https://github.com/nodejh/hugo-theme-mini

@morisono
Copy link

@morisono
Copy link

@morisono
Copy link

@morisono
Copy link

@morisono
Copy link

@morisono
Copy link

morisono commented Oct 14, 2024

Wikiのダウンロードは、.wikiをつける

ghq get $url.wiki.git

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment