diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..39c428d --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,29 @@ +{ + "name": "Jekyll", + "image": "mcr.microsoft.com/devcontainers/jekyll:2-bullseye", + "onCreateCommand": "git config --global --add safe.directory ${containerWorkspaceFolder}", + "postCreateCommand": "bash .devcontainer/post-create.sh", + "customizations": { + "vscode": { + "settings": { + "terminal.integrated.defaultProfile.linux": "zsh" + }, + "extensions": [ + // Liquid tags auto-complete + "killalau.vscode-liquid-snippets", + // Liquid syntax highlighting and formatting + "Shopify.theme-check-vscode", + // Shell + "timonwong.shellcheck", + "mkhl.shfmt", + // Common formatter + "EditorConfig.EditorConfig", + "esbenp.prettier-vscode", + "stylelint.vscode-stylelint", + "yzhang.markdown-all-in-one", + // Git + "mhutchie.git-graph" + ] + } + } +} diff --git a/.devcontainer/post-create.sh b/.devcontainer/post-create.sh new file mode 100644 index 0000000..a4bc282 --- /dev/null +++ b/.devcontainer/post-create.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +if [ -f package.json ]; then + bash -i -c "nvm install --lts && nvm install-latest-npm" + npm i + npm run build +fi + +# Install dependencies for shfmt extension +curl -sS https://webi.sh/shfmt | sh &>/dev/null + +# Add OMZ plugins +git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting +git clone https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions +sed -i -E "s/^(plugins=\()(git)(\))/\1\2 zsh-syntax-highlighting zsh-autosuggestions\3/" ~/.zshrc + +# Avoid git log use less +echo -e "\nunset LESS" >>~/.zshrc diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..2b740bf --- /dev/null +++ b/.editorconfig @@ -0,0 +1,19 @@ +root = true + +[*] +charset = utf-8 +indent_style = space +indent_size = 2 +trim_trailing_whitespace = true +# Unix-style newlines with a newline ending every file +end_of_line = lf +insert_final_newline = true + +[*.{js,css,scss}] +quote_type = single + +[*.{yml,yaml}] +quote_type = double + +[*.md] +trim_trailing_whitespace = false diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..262d6bd --- /dev/null +++ b/.gitattributes @@ -0,0 +1,16 @@ +# Set default behavior to automatically normalize line endings. +* text=auto + +# Force bash scripts to always use LF line endings so that if a repo is accessed +# in Unix via a file share from Windows, the scripts will work. +*.sh text eol=lf + +# Force batch scripts to always use CRLF line endings so that if a repo is accessed +# in Windows via a file share from Linux, the scripts will work. +*.{cmd,[cC][mM][dD]} text eol=crlf +*.{bat,[bB][aA][tT]} text eol=crlf + +# Denote all files that are truly binary and should not be modified. +*.png binary +*.jpg binary +*.ico binary diff --git a/.github/workflows/pages-deploy.yml b/.github/workflows/pages-deploy.yml new file mode 100644 index 0000000..cc28f99 --- /dev/null +++ b/.github/workflows/pages-deploy.yml @@ -0,0 +1,73 @@ +name: "Build and Deploy" +on: + push: + branches: + - main + - master + paths-ignore: + - .gitignore + - README.md + - LICENSE + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +permissions: + contents: read + pages: write + id-token: write + +# Allow one concurrent deployment +concurrency: + group: "pages" + cancel-in-progress: true + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + # submodules: true + # If using the 'assets' git submodule from Chirpy Starter, uncomment above + # (See: https://github.com/cotes2020/chirpy-starter/tree/main/assets) + + - name: Setup Pages + id: pages + uses: actions/configure-pages@v4 + + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.3 + bundler-cache: true + + - name: Build site + run: bundle exec jekyll b -d "_site${{ steps.pages.outputs.base_path }}" + env: + JEKYLL_ENV: "production" + + - name: Test site + run: | + bundle exec htmlproofer _site \ + \-\-disable-external \ + \-\-ignore-urls "/^http:\/\/127.0.0.1/,/^http:\/\/0.0.0.0/,/^http:\/\/localhost/" + + - name: Upload site artifact + uses: actions/upload-pages-artifact@v3 + with: + path: "_site${{ steps.pages.outputs.base_path }}" + + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + needs: build + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0082d90 --- /dev/null +++ b/.gitignore @@ -0,0 +1,27 @@ +# Bundler cache +.bundle +vendor +Gemfile.lock + +# Jekyll cache +.jekyll-cache +.jekyll-metadata +_site + +# RubyGems +*.gem + +# NPM dependencies +node_modules +package-lock.json + +# IDE configurations +.idea +.vscode/* +!.vscode/settings.json +!.vscode/extensions.json +!.vscode/tasks.json + +# Misc +_sass/dist +assets/js/dist diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..58062c5 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "assets/lib"] + path = assets/lib + url = https://github.com/cotes2020/chirpy-static-assets.git diff --git a/.nojekyll b/.nojekyll new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/.nojekyll @@ -0,0 +1 @@ + diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..082bc94 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,3 @@ +{ + "recommendations": ["ms-vscode-remote.remote-containers"] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..5e8a04f --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,30 @@ +{ + // Prettier + "editor.defaultFormatter": "esbenp.prettier-vscode", + "editor.formatOnSave": true, + // Shopify Liquid + "files.associations": { + "*.html": "liquid" + }, + "[markdown]": { + "editor.defaultFormatter": "yzhang.markdown-all-in-one" + }, + // Formatter + "[html][liquid]": { + "editor.defaultFormatter": "Shopify.theme-check-vscode" + }, + "[shellscript]": { + "editor.defaultFormatter": "mkhl.shfmt" + }, + // Disable vscode built-in stylelint + "css.validate": false, + "scss.validate": false, + "less.validate": false, + // Stylint extension settings + "stylelint.snippet": ["css", "scss"], + "stylelint.validate": ["css", "scss"], + // Run tasks in macOS + "terminal.integrated.profiles.osx": { + "zsh": { "path": "/bin/zsh", "args": ["-l", "-i"] } + } +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..7f0fdb8 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,26 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "Run Jekyll Server", + "type": "shell", + "command": "./tools/run.sh", + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": [], + "detail": "Runs the Jekyll server with live reload." + }, + { + "label": "Build Jekyll Site", + "type": "shell", + "command": "./tools/test.sh", + "group": { + "kind": "build" + }, + "problemMatcher": [], + "detail": "Build the Jekyll site for production." + } + ] +} diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..dbd3872 --- /dev/null +++ b/Gemfile @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +gem "jekyll-theme-chirpy", "~> 7.1", ">= 7.1.1" + +gem "html-proofer", "~> 5.0", group: :test + +platforms :mingw, :x64_mingw, :mswin, :jruby do + gem "tzinfo", ">= 1", "< 3" + gem "tzinfo-data" +end + +gem "wdm", "~> 0.1.1", :platforms => [:mingw, :x64_mingw, :mswin] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a6f6c9f --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Cotes Chung + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..793cd08 --- /dev/null +++ b/README.md @@ -0,0 +1,43 @@ +# Chirpy Starter + +[![Gem Version](https://img.shields.io/gem/v/jekyll-theme-chirpy)][gem]  +[![GitHub license](https://img.shields.io/github/license/cotes2020/chirpy-starter.svg?color=blue)][mit] + +When installing the [**Chirpy**][chirpy] theme through [RubyGems.org][gem], Jekyll can only read files in the folders +`_data`, `_layouts`, `_includes`, `_sass` and `assets`, as well as a small part of options of the `_config.yml` file +from the theme's gem. If you have ever installed this theme gem, you can use the command +`bundle info --path jekyll-theme-chirpy` to locate these files. + +The Jekyll team claims that this is to leave the ball in the user’s court, but this also results in users not being +able to enjoy the out-of-the-box experience when using feature-rich themes. + +To fully use all the features of **Chirpy**, you need to copy the other critical files from the theme's gem to your +Jekyll site. The following is a list of targets: + +```shell +. +├── _config.yml +├── _plugins +├── _tabs +└── index.html +``` + +To save you time, and also in case you lose some files while copying, we extract those files/configurations of the +latest version of the **Chirpy** theme and the [CD][CD] workflow to here, so that you can start writing in minutes. + +## Usage + +Check out the [theme's docs](https://github.com/cotes2020/jekyll-theme-chirpy/wiki). + +## Contributing + +This repository is automatically updated with new releases from the theme repository. If you encounter any issues or want to contribute to its improvement, please visit the [theme repository][chirpy] to provide feedback. + +## License + +This work is published under [MIT][mit] License. + +[gem]: https://rubygems.org/gems/jekyll-theme-chirpy +[chirpy]: https://github.com/cotes2020/jekyll-theme-chirpy/ +[CD]: https://en.wikipedia.org/wiki/Continuous_deployment +[mit]: https://github.com/cotes2020/chirpy-starter/blob/master/LICENSE diff --git a/_config.yml b/_config.yml new file mode 100644 index 0000000..9f75866 --- /dev/null +++ b/_config.yml @@ -0,0 +1,225 @@ +# The Site Configuration + +# Import the theme +theme: jekyll-theme-chirpy + +# The language of the webpage › http://www.lingoes.net/en/translator/langcode.htm +# If it has the same name as one of the files in folder `_data/locales`, the layout language will also be changed, +# otherwise, the layout language will use the default value of 'en'. +lang: en + +# Change to your timezone › https://kevinnovak.github.io/Time-Zone-Picker +timezone: + +# jekyll-seo-tag settings › https://github.com/jekyll/jekyll-seo-tag/blob/master/docs/usage.md +# ↓ -------------------------- + +title: Chirpy # the main title + +tagline: A text-focused Jekyll theme # it will display as the subtitle + +description: >- # used by seo meta and the atom feed + A minimal, responsive and feature-rich Jekyll theme for technical writing. + +# Fill in the protocol & hostname for your site. +# E.g. 'https://username.github.io', note that it does not end with a '/'. +url: "" + +github: + username: github_username # change to your GitHub username + +twitter: + username: twitter_username # change to your Twitter username + +social: + # Change to your full name. + # It will be displayed as the default author of the posts and the copyright owner in the Footer + name: your_full_name + email: example@domain.com # change to your email address + links: + # The first element serves as the copyright owner's link + - https://twitter.com/username # change to your Twitter homepage + - https://github.com/username # change to your GitHub homepage + # Uncomment below to add more social links + # - https://www.facebook.com/username + # - https://www.linkedin.com/in/username + +# Site Verification Settings +webmaster_verifications: + google: # fill in your Google verification code + bing: # fill in your Bing verification code + alexa: # fill in your Alexa verification code + yandex: # fill in your Yandex verification code + baidu: # fill in your Baidu verification code + facebook: # fill in your Facebook verification code + +# ↑ -------------------------- +# The end of `jekyll-seo-tag` settings + +# Web Analytics Settings +analytics: + google: + id: # fill in your Google Analytics ID + goatcounter: + id: # fill in your GoatCounter ID + umami: + id: # fill in your Umami ID + domain: # fill in your Umami domain + matomo: + id: # fill in your Matomo ID + domain: # fill in your Matomo domain + cloudflare: + id: # fill in your Cloudflare Web Analytics token + fathom: + id: # fill in your Fathom Site ID + +# Page views settings +pageviews: + provider: # now only supports 'goatcounter' + +# Prefer color scheme setting. +# +# Note: Keep empty will follow the system prefer color by default, +# and there will be a toggle to switch the theme between dark and light +# on the bottom left of the sidebar. +# +# Available options: +# +# light — Use the light color scheme +# dark — Use the dark color scheme +# +theme_mode: # [light | dark] + +# The CDN endpoint for media resources. +# Notice that once it is assigned, the CDN url +# will be added to all media resources (site avatar, posts' images, audio and video files) paths starting with '/' +# +# e.g. 'https://cdn.com' +cdn: + +# the avatar on sidebar, support local or CORS resources +avatar: + +# The URL of the site-wide social preview image used in SEO `og:image` meta tag. +# It can be overridden by a customized `page.image` in front matter. +social_preview_image: # string, local or CORS resources + +# boolean type, the global switch for TOC in posts. +toc: true + +comments: + # Global switch for the post-comment system. Keeping it empty means disabled. + provider: # [disqus | utterances | giscus] + # The provider options are as follows: + disqus: + shortname: # fill with the Disqus shortname. › https://help.disqus.com/en/articles/1717111-what-s-a-shortname + # utterances settings › https://utteranc.es/ + utterances: + repo: # / + issue_term: # < url | pathname | title | ...> + # Giscus options › https://giscus.app + giscus: + repo: # / + repo_id: + category: + category_id: + mapping: # optional, default to 'pathname' + strict: # optional, default to '0' + input_position: # optional, default to 'bottom' + lang: # optional, default to the value of `site.lang` + reactions_enabled: # optional, default to the value of `1` + +# Self-hosted static assets, optional › https://github.com/cotes2020/chirpy-static-assets +assets: + self_host: + enabled: # boolean, keep empty means false + # specify the Jekyll environment, empty means both + # only works if `assets.self_host.enabled` is 'true' + env: # [development | production] + +pwa: + enabled: true # The option for PWA feature (installable) + cache: + enabled: true # The option for PWA offline cache + # Paths defined here will be excluded from the PWA cache. + # Usually its value is the `baseurl` of another website that + # shares the same domain name as the current website. + deny_paths: + # - "/example" # URLs match `/example/*` will not be cached by the PWA + +paginate: 10 + +# The base URL of your site +baseurl: "" + +# ------------ The following options are not recommended to be modified ------------------ + +kramdown: + footnote_backlink: "↩︎" + syntax_highlighter: rouge + syntax_highlighter_opts: # Rouge Options › https://github.com/jneen/rouge#full-options + css_class: highlight + # default_lang: console + span: + line_numbers: false + block: + line_numbers: true + start_line: 1 + +collections: + tabs: + output: true + sort_by: order + +defaults: + - scope: + path: "" # An empty string here means all files in the project + type: posts + values: + layout: post + comments: true # Enable comments in posts. + toc: true # Display TOC column in posts. + # DO NOT modify the following parameter unless you are confident enough + # to update the code of all other post links in this project. + permalink: /posts/:title/ + - scope: + path: _drafts + values: + comments: false + - scope: + path: "" + type: tabs # see `site.collections` + values: + layout: page + permalink: /:title/ + +sass: + style: compressed + +compress_html: + clippings: all + comments: all + endings: all + profile: false + blanklines: false + ignore: + envs: [development] + +exclude: + - "*.gem" + - "*.gemspec" + - docs + - tools + - README.md + - LICENSE + - "*.config.js" + - package*.json + +jekyll-archives: + enabled: [categories, tags] + layouts: + category: category + tag: tag + permalinks: + tag: /tags/:name/ + category: /categories/:name/ diff --git a/_data/contact.yml b/_data/contact.yml new file mode 100644 index 0000000..ed40acb --- /dev/null +++ b/_data/contact.yml @@ -0,0 +1,40 @@ +# The contact options. + +- type: github + icon: "fab fa-github" + +- type: twitter + icon: "fa-brands fa-x-twitter" + +- type: email + icon: "fas fa-envelope" + noblank: true # open link in current tab + +- type: rss + icon: "fas fa-rss" + noblank: true +# Uncomment and complete the url below to enable more contact options +# +# - type: mastodon +# icon: 'fab fa-mastodon' # icons powered by +# url: '' # Fill with your Mastodon account page, rel="me" will be applied for verification +# +# - type: linkedin +# icon: 'fab fa-linkedin' # icons powered by +# url: '' # Fill with your Linkedin homepage +# +# - type: stack-overflow +# icon: 'fab fa-stack-overflow' +# url: '' # Fill with your stackoverflow homepage +# +# - type: bluesky +# icon: 'fa-brands fa-bluesky' +# url: '' # Fill with your Bluesky profile link +# +# - type: reddit +# icon: 'fa-brands fa-reddit' +# url: '' # Fill with your Reddit profile link +# +# - type: threads +# icon: 'fa-brands fa-threads' +# url: '' # Fill with your Threads profile link diff --git a/_data/share.yml b/_data/share.yml new file mode 100644 index 0000000..6f97568 --- /dev/null +++ b/_data/share.yml @@ -0,0 +1,50 @@ +# Sharing options at the bottom of the post. +# Icons from + +platforms: + - type: Twitter + icon: "fa-brands fa-square-x-twitter" + link: "https://twitter.com/intent/tweet?text=TITLE&url=URL" + + - type: Facebook + icon: "fab fa-facebook-square" + link: "https://www.facebook.com/sharer/sharer.php?title=TITLE&u=URL" + + - type: Telegram + icon: "fab fa-telegram" + link: "https://t.me/share/url?url=URL&text=TITLE" + + # Uncomment below if you need to. + # + # - type: Linkedin + # icon: "fab fa-linkedin" + # link: "https://www.linkedin.com/sharing/share-offsite/?url=URL" + # + # - type: Weibo + # icon: "fab fa-weibo" + # link: "https://service.weibo.com/share/share.php?title=TITLE&url=URL" + # + # - type: Mastodon + # icon: "fa-brands fa-mastodon" + # # See: https://github.com/justinribeiro/share-to-mastodon#properties + # instances: + # - label: mastodon.social + # link: "https://mastodon.social/" + # - label: mastodon.online + # link: "https://mastodon.online/" + # - label: fosstodon.org + # link: "https://fosstodon.org/" + # - label: photog.social + # link: "https://photog.social/" + # + # - type: Bluesky + # icon: "fa-brands fa-bluesky" + # link: "https://bsky.app/intent/compose?text=TITLE%20URL" + # + # - type: Reddit + # icon: "fa-brands fa-square-reddit" + # link: "https://www.reddit.com/submit?url=URL&title=TITLE" + # + # - type: Threads + # icon: "fa-brands fa-square-threads" + # link: "https://www.threads.net/intent/post?text=TITLE%20URL" diff --git a/_plugins/posts-lastmod-hook.rb b/_plugins/posts-lastmod-hook.rb new file mode 100644 index 0000000..1fd6ecf --- /dev/null +++ b/_plugins/posts-lastmod-hook.rb @@ -0,0 +1,14 @@ +#!/usr/bin/env ruby +# +# Check for changed posts + +Jekyll::Hooks.register :posts, :post_init do |post| + + commit_num = `git rev-list --count HEAD "#{ post.path }"` + + if commit_num.to_i > 1 + lastmod_date = `git log -1 --pretty="%ad" --date=iso "#{ post.path }"` + post.data['last_modified_at'] = lastmod_date + end + +end diff --git a/_posts/.placeholder b/_posts/.placeholder new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/_posts/.placeholder @@ -0,0 +1 @@ + diff --git a/_tabs/about.md b/_tabs/about.md new file mode 100644 index 0000000..ddb2bc4 --- /dev/null +++ b/_tabs/about.md @@ -0,0 +1,8 @@ +--- +# the default layout is 'page' +icon: fas fa-info-circle +order: 4 +--- + +> Add Markdown syntax content to file `_tabs/about.md`{: .filepath } and it will show up on this page. +{: .prompt-tip } diff --git a/_tabs/archives.md b/_tabs/archives.md new file mode 100644 index 0000000..c3abc59 --- /dev/null +++ b/_tabs/archives.md @@ -0,0 +1,5 @@ +--- +layout: archives +icon: fas fa-archive +order: 3 +--- diff --git a/_tabs/categories.md b/_tabs/categories.md new file mode 100644 index 0000000..2d241be --- /dev/null +++ b/_tabs/categories.md @@ -0,0 +1,5 @@ +--- +layout: categories +icon: fas fa-stream +order: 1 +--- diff --git a/_tabs/tags.md b/_tabs/tags.md new file mode 100644 index 0000000..ded3adc --- /dev/null +++ b/_tabs/tags.md @@ -0,0 +1,5 @@ +--- +layout: tags +icon: fas fa-tags +order: 2 +--- diff --git a/assets/lib b/assets/lib new file mode 160000 index 0000000..a231bc7 --- /dev/null +++ b/assets/lib @@ -0,0 +1 @@ +Subproject commit a231bc7e2c67198e604950cb2be9147a0b2020c0 diff --git a/index.html b/index.html new file mode 100644 index 0000000..1357b08 --- /dev/null +++ b/index.html @@ -0,0 +1,4 @@ +--- +layout: home +# Index page +--- diff --git a/tools/run.sh b/tools/run.sh new file mode 100755 index 0000000..0efc452 --- /dev/null +++ b/tools/run.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash +# +# Run jekyll serve and then launch the site + +prod=false +command="bundle exec jekyll s -l" +host="127.0.0.1" + +help() { + echo "Usage:" + echo + echo " bash /path/to/run [options]" + echo + echo "Options:" + echo " -H, --host [HOST] Host to bind to." + echo " -p, --production Run Jekyll in 'production' mode." + echo " -h, --help Print this help information." +} + +while (($#)); do + opt="$1" + case $opt in + -H | --host) + host="$2" + shift 2 + ;; + -p | --production) + prod=true + shift + ;; + -h | --help) + help + exit 0 + ;; + *) + echo -e "> Unknown option: '$opt'\n" + help + exit 1 + ;; + esac +done + +command="$command -H $host" + +if $prod; then + command="JEKYLL_ENV=production $command" +fi + +if [ -e /proc/1/cgroup ] && grep -q docker /proc/1/cgroup; then + command="$command --force_polling" +fi + +echo -e "\n> $command\n" +eval "$command" diff --git a/tools/test.sh b/tools/test.sh new file mode 100755 index 0000000..331de1c --- /dev/null +++ b/tools/test.sh @@ -0,0 +1,89 @@ +#!/usr/bin/env bash +# +# Build and test the site content +# +# Requirement: html-proofer, jekyll +# +# Usage: See help information + +set -eu + +SITE_DIR="_site" + +_config="_config.yml" + +_baseurl="" + +help() { + echo "Build and test the site content" + echo + echo "Usage:" + echo + echo " bash $0 [options]" + echo + echo "Options:" + echo ' -c, --config "" Specify config file(s)' + echo " -h, --help Print this information." +} + +read_baseurl() { + if [[ $_config == *","* ]]; then + # multiple config + IFS="," + read -ra config_array <<<"$_config" + + # reverse loop the config files + for ((i = ${#config_array[@]} - 1; i >= 0; i--)); do + _tmp_baseurl="$(grep '^baseurl:' "${config_array[i]}" | sed "s/.*: *//;s/['\"]//g;s/#.*//")" + + if [[ -n $_tmp_baseurl ]]; then + _baseurl="$_tmp_baseurl" + break + fi + done + + else + # single config + _baseurl="$(grep '^baseurl:' "$_config" | sed "s/.*: *//;s/['\"]//g;s/#.*//")" + fi +} + +main() { + # clean up + if [[ -d $SITE_DIR ]]; then + rm -rf "$SITE_DIR" + fi + + read_baseurl + + # build + JEKYLL_ENV=production bundle exec jekyll b \ + -d "$SITE_DIR$_baseurl" -c "$_config" + + # test + bundle exec htmlproofer "$SITE_DIR" \ + --disable-external \ + --ignore-urls "/^http:\/\/127.0.0.1/,/^http:\/\/0.0.0.0/,/^http:\/\/localhost/" +} + +while (($#)); do + opt="$1" + case $opt in + -c | --config) + _config="$2" + shift + shift + ;; + -h | --help) + help + exit 0 + ;; + *) + # unknown option + help + exit 1 + ;; + esac +done + +main