Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Cherng <[email protected]>
  • Loading branch information
jfcherng committed Oct 25, 2022
0 parents commit 53466d5
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: https://www.paypal.me/jfcherng/5usd
62 changes: 62 additions & 0 deletions .github/workflows/mirror.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Mirror Sublime HQ documents

on:
push:
branches:
- '*'
pull_request:
branches:
- '*'
schedule:
# @see https://crontab.guru
- cron: '0 3 */1 * *'

jobs:
mirror:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Prepare
run: |
sudo apt install -y httrack
- name: Environment Variables
run: |
NOW="$(date +'%Y/%m/%d %H:%M:%S')"
echo "NOW=$NOW" >> $GITHUB_ENV
TODAY="$(date +'%Y%m%d')"
echo "TODAY=$TODAY" >> $GITHUB_ENV
SM_DIR="SM_official_docs_${TODAY}"
SM_ZIP="$SM_DIR.${{ github.run_number }}.zip"
echo "SM_DIR=$SM_DIR" >> $GITHUB_ENV
echo "SM_ZIP=$SM_ZIP" >> $GITHUB_ENV
ST_DIR="ST_official_docs_${TODAY}"
ST_ZIP="$ST_DIR.${{ github.run_number }}.zip"
echo "ST_DIR=$ST_DIR" >> $GITHUB_ENV
echo "ST_ZIP=$ST_ZIP" >> $GITHUB_ENV
- name: Mirror
run: |
./scripts/mirror_official_docs.sh
tree .
pushd scripts/docs/
zip -9ry "${{ github.workspace }}/${{ env.SM_ZIP }}" "${{ env.SM_DIR }}"
zip -9ry "${{ github.workspace }}/${{ env.ST_ZIP }}" "${{ env.ST_DIR }}"
popd
- name: Release
uses: ncipollo/release-action@v1
with:
draft: false
prerelease: false
allowUpdates: true
artifactErrorsFailBuild: true
token: ${{ secrets.ACCESS_TOKEN }}
tag: v${{ env.TODAY }}.${{ github.run_number }}
body: Mirrored documents on ${{ env.TODAY }}.
artifacts: ${{ env.SM_ZIP }},${{ env.ST_ZIP }}
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Sublime HQ Documents Mirror

This repository releases mirror offline official Sublime Text/Merge documents periodically.

## Download

Check the [release page][release-page].

[release-page]: https://github.com/jfcherng-sublime/sublime-hq-documents-mirror/releases
89 changes: 89 additions & 0 deletions scripts/mirror_official_docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/usr/bin/env bash

SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
NOW="$(date +'%Y/%m/%d %H:%M:%S')"
TODAY="$(date +'%Y%m%d')"

# ------ #
# colors #
# ------ #

if [[ ${FORCE_COLOR} == "0" ]]; then
C_RESET=""
H_DEBUG="[DEBUG]"
H_INFO="[INFO]"
H_WARNING="[WARNING]"
H_ERROR="[ERROR]"
else
C_RESET="\e[0m"
H_DEBUG="[\e[0;30;47mDEBUG${C_RESET}]"
H_INFO="[\e[0;37;44mINFO${C_RESET}]"
H_WARNING="[\e[0;30;43mWARNING${C_RESET}]"
H_ERROR="[\e[0;37;41mERROR${C_RESET}]"
fi

#---------#
# configs #
#---------#

HTTRACK=${HTTRACK:-"httrack"}
USER_AGENT=${USER_AGENT-"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36"}
FOOTER=${FOOTER-"<div style='text-align:center; background:#ffff6e'>Snapshot on ${NOW}</div>"}

function mirror() {
local output_dir="$1"
local start_url="$2"

rm -rf "${output_dir}"

pushd "${SCRIPT_DIR}" || exit

echo -e "${H_INFO} ⌛ Downloading..."

"${HTTRACK}" \
--path "${output_dir}" \
--user-agent "${USER_AGENT}" \
--referer "${start_url}" \
--mirror "${start_url}" \
--footer "${FOOTER}" \
--stay-on-same-address \
--quiet \
--max-rate=0 \
+*.png +*.gif +*.jpg +*.jpeg +*.webp +*.svg +*.css +*.js \
-ad.doubleclick.net/*

# redirect index page to website index
index_file="${output_dir}/index.html"
if [ -f "${index_file}" ]; then
index_url=$(sed -zE 's/.* HREF="([^"]+)".*/\1/g' "${index_file}")
echo "<meta http-equiv='refresh' content='0; url=${index_url}' />" \
>"${output_dir}/index.html"
fi

cleanup "${output_dir}"

popd || exit
}

function cleanup() {
local output_dir="$1"

pushd "${output_dir}" || exit

echo -e "${H_INFO} 🧹 Clean up..."

rm -rf \
hts-cache/ \
hts-log.txt \
./*.gif

popd || exit
}

mirror \
"${SCRIPT_DIR}/docs/ST_official_docs_${TODAY}" \
"https://www.sublimetext.com/docs/index.html"

mirror \
"${SCRIPT_DIR}/docs/SM_official_docs_${TODAY}" \
"https://www.sublimemerge.com/docs/index.html"

0 comments on commit 53466d5

Please sign in to comment.