Skip to content

Commit

Permalink
change to HackMD
Browse files Browse the repository at this point in the history
  • Loading branch information
taichunmin committed Feb 27, 2025
1 parent 766e5eb commit 6ab58df
Show file tree
Hide file tree
Showing 11 changed files with 1,030 additions and 497 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup Pages
uses: actions/configure-pages@v3
uses: actions/configure-pages@v5
- name: Setup Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 18
cache: 'yarn'
node-version: latest
cache: yarn
- name: 編譯網頁
env:
BASEURL: ${{ secrets.BASEURL }}
Expand All @@ -45,9 +45,9 @@ jobs:
env:
CNAME: ${{ secrets.CNAME }}
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
uses: actions/upload-pages-artifact@v3
with:
path: './dist'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
uses: actions/deploy-pages@v4
2 changes: 1 addition & 1 deletion component/gtag.pug
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ if GTAG_ID
;(() => {
// initialize gtag
window.dataLayer = window.dataLayer || []
function gtag(){window.dataLayer.push(arguments)}
function gtag () { window.dataLayer.push(arguments) }
gtag.id = '#{GTAG_ID}'
gtag('js', new Date())
gtag('config', gtag.id)
Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,29 @@
},
"dependencies": {
"cross-env": "^7.0.3",
"dayjs": "^1.11.9",
"debug": "^4.3.4",
"dotenv": "^16.3.1",
"fast-glob": "^3.3.1",
"dayjs": "^1.11.13",
"debug": "^4.4.0",
"dotenv": "^16.4.7",
"fast-glob": "^3.3.3",
"html-minifier": "^4.0.0",
"jstransformer-sass": "^1.0.0",
"ncp": "^2.0.0",
"node-forge": "^1.3.1",
"pug": "^3.0.2",
"uglify-js": "^3.17.4"
"pug": "^3.0.3",
"uglify-js": "^3.19.3"
},
"devDependencies": {
"eslint": "^8.47.0",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-n": "^16.0.2",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-n": "^17.15.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-promise": "^7.2.1",
"eslint-plugin-pug": "^1.2.5",
"finalhandler": "^1.2.0",
"finalhandler": "^1.3.1",
"livereload": "^0.9.3",
"node-watch": "^0.7.4",
"serve-static": "^1.15.0"
"serve-static": "^1.16.2"
},
"resolutions": {
"**/jstransformer-scss": "^2.0.0"
Expand Down
2 changes: 1 addition & 1 deletion src/forms/acnh-passport-1.pug
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ block form
.form-group.was-validated.my-2
label(for="vcard-avator") 大頭照
input#vcard-avator.form-control.form-control-sm(type="url", inputmode="url", required, pattern="https://\\S+", v-model.trim="vcard.avator")
small.form-text.text-muted 請填寫大頭照圖片網址,必須是 #[code https://] 開頭,比例為 #[code 1:1],建議可將圖片#[a(target="_blank", href="https://imgur.com/") 上傳到 Imgur 圖床]#[a(href="https://docs.google.com/spreadsheets/d/13d_LAJPlxMa_DubPTuirkIV4DERBMXbrWQsmSh8ReK4/edit#gid=1696242249", target="_blank") 居民大頭貼請點此]
small.form-text.text-muted 請填寫大頭照圖片網址,必須是 #[code https://] 開頭,比例為 #[code 1:1],建議可將圖片#[a(target="_blank", href="https://hackmd.io/@docs/how_to_upload_image_tw") 上傳到 HackMD]#[a(href="https://docs.google.com/spreadsheets/d/13d_LAJPlxMa_DubPTuirkIV4DERBMXbrWQsmSh8ReK4/edit#gid=1696242249", target="_blank") 居民大頭貼請點此]
.form-group.was-validated.my-2
label(for="vcard-title") 頭銜
input#vcard-title.form-control.form-control-sm(type="text", required, pattern=".+", v-model="vcard.title")
Expand Down
2 changes: 1 addition & 1 deletion src/forms/facebook-post-link-1.pug
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ block form
.form-group.was-validated.my-2
label(for="vcard-image") 預覽圖
input#vcard-image.form-control.form-control-sm(type="url", inputmode="url", required, pattern="https://\\S+", v-model.trim="vcard.image")
small.form-text.text-muted 請填寫連結的預覽圖,必須是 #[code https://] 開頭,建議可將圖片#[a(target="_blank", href="https://imgur.com/") 上傳到 Imgur 圖床]
small.form-text.text-muted 請填寫連結的預覽圖,必須是 #[code https://] 開頭,建議可將圖片#[a(target="_blank", href="https://hackmd.io/@docs/how_to_upload_image_tw") 上傳到 HackMD]
.form-group.was-validated.my-2
label(for="vcard-ratio") 預覽圖的長寬比
input#vcard-ratio.form-control.form-control-sm(type="text", required, pattern="\\d+:\\d+", v-model="vcard.ratio")
Expand Down
2 changes: 1 addition & 1 deletion src/forms/line-carousel-1.pug
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ block form
.form-group.was-validated.mb-2
label(for="vcard-image") 卡片圖片網址 (長寬比 #[code {{ vcard.json5.ratio }}])
input#vcard-image.form-control.form-control-sm(type="url", inputmode="url", required, pattern="https://\\S+", v-model.trim="curCard.image")
small.form-text.text-muted 請填寫卡片圖片網址,必須是 #[code https://] 開頭,建議可將圖片#[a(target="_blank", href="https://imgur.com/") 上傳到 Imgur 圖床]
small.form-text.text-muted 請填寫卡片圖片網址,必須是 #[code https://] 開頭,建議可將圖片#[a(target="_blank", href="https://hackmd.io/@docs/how_to_upload_image_tw") 上傳到 HackMD]
a.d-block.mt-2(v-if="curCardImgPreview", target="_blank", :href="curCardImgPreview")
img(:src="curCardImgPreview", :key="curCardImgPreview", style="width: 100%; max-width: 200px")
ul.list-group.list-group-flush
Expand Down
2 changes: 1 addition & 1 deletion src/forms/psprint-3949.pug
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ block form
.form-group.was-validated.my-2
label(for="vcard-logo") LOGO
input#vcard-logo.form-control.form-control-sm(type="url", inputmode="url", required, pattern="https://\\S+", v-model.trim="vcard.logo")
small.form-text.text-muted 請填寫 LOGO 圖片網址,必須是 #[code https://] 開頭,比例為 #[code 1:1],建議可將圖片#[a(target="_blank", href="https://imgur.com/") 上傳到 Imgur 圖床]
small.form-text.text-muted 請填寫 LOGO 圖片網址,必須是 #[code https://] 開頭,比例為 #[code 1:1],建議可將圖片#[a(target="_blank", href="https://hackmd.io/@docs/how_to_upload_image_tw") 上傳到 HackMD]
.form-group.was-validated.my-2
label(for="vcard-name") 姓名
input#vcard-name.form-control.form-control-sm(type="text", required, pattern=".+", v-model="vcard.name")
Expand Down
16 changes: 13 additions & 3 deletions src/js/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,13 @@

const decodeGzip = (() => {
const cBase64 = CryptoJS.enc.Base64
const inflate = window.pako.inflate
const inflate = (...args) => {
try {
window?.pako?.inflate?.(...args)
} catch (err) {
throw new Error(`pako.inflate: ${err.message ?? err}`)
}
}
const urlToBase64 = str => str.replace(/[-_]/g, c => _.get({ '-': '+', _: '/' }, c))
const wordToArrayBuffer = wordArr => {
const len = wordArr.words.length
Expand All @@ -69,8 +75,12 @@
return view.buffer.slice(0, wordArr.sigBytes)
}
return base64 => {
const buffer = wordToArrayBuffer(cBase64.parse(urlToBase64(base64)))
return inflate(new Uint8Array(buffer), { to: 'string' })
try {
const buffer = wordToArrayBuffer(cBase64.parse(urlToBase64(base64)))
return inflate(new Uint8Array(buffer), { to: 'string' })
} catch (err) {
throw _.set(new Error(`decodeGzip: ${err.message}`), 'originalError', err)
}
}
})()

Expand Down
3 changes: 1 addition & 2 deletions src/liff-full/share-json5gzip.pug
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ block vue-config
try {
this.vcard = window.parseJsonOrDefault(this.paramGzip('json5gzip'), {})
} catch (err) {
err.message = `${this.$t('csv.getVcardFail')}${err.message ? ': ' + err.message : ''}`
this.render = null
throw err
throw _.set(new Error(err.message), 'originalError', err)
}
},
}
11 changes: 6 additions & 5 deletions src/liff-full/share.pug
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ block script
script(crossorigin="anonymous", src="https://static.line-scdn.net/liff/edge/2/sdk.js")
script(crossorigin="anonymous", src="https://cdn.jsdelivr.net/gh/PamornT/flex2html@main/js/flex2html.min.js")
script.
/** global gtag */
const loginPromise = (async () => {
await liff.init({ liffId: '#{liffidFull}' })
if (window.getSearchParam('liff.state')) await new Promise(resolve => {}) // 永遠不會結束的 Promise
Expand Down Expand Up @@ -109,9 +110,10 @@ block script
},
methods: {
async getTpl () {
const { gtag } = window
try {
const tpl = this.paramBase64url('template')
if (!tpl) throw new Error('template is required.')
if (_.isNil(tpl)) throw new Error('template is required.')
const render = _.template(_.get(await axios.get(tpl, {
params: { cachebust: Date.now() },
transformResponse: [],
Expand All @@ -121,10 +123,9 @@ block script
const { profile = {} } = this

// generate fake page_view for template_impression
const baks = _.fromPairs(await Promise.all(['client_id', 'session_id', 'user_id'], async k => {
const val = await new Promise(resolve, gtag('get', gtag.id, k, resolve))
return [k, val]
}))
const baks = _.fromPairs(await Promise.all(_.map(['client_id', 'session_id', 'user_id'], async k => {
return [k, await new Promise(resolve => { gtag('get', gtag.id, k, resolve) })]
})))
// generate clientId by line userId
const gtagClientId = gtag.genClientIdByLineId(profile.userId)
const gtagSessionId = `${liff.getDecodedIDToken()?.iat ?? Math.trunc(Date.now() / 1e3)}`
Expand Down
Loading

0 comments on commit 6ab58df

Please sign in to comment.