WordPress: Format and colorize code block by applying prism.js

Motivations

for (int i = 5; i < 10 ; i++) {
    Console.WriteLine("Hello Moto?");
}

If you are using Vantage for your WordPress site, and you want to make your code block looks fancy, follow the instructions:

Instructions

1. Make sure you have created a child theme based on Vantage, and it's activated.

2. Reset styles applied to code block.

I highly recommend to work with WP-SCSS plugin when writing CSS/SCSS, so you can have stylesheets organized without the costs of performance by using @import.

/* Reset the style set by Vantage (the parent theme) */
.entry-content pre, .entry-content code {
    background: unset;
    font-family: unset;
    border: unset;
    box-shadow: unset;
    overflow-x: unset;
}

Later we will apply prism.js and its stylesheet.

3. Insert code snippits to your child theme's "functions.php"

function code_pre_theme(){
    // To check if currently viewing page is a "post"
    if (is_singular('post')) {
        wp_enqueue_script('prism-js', 'https://cdn.jsdelivr.net/npm/[email protected]/prism.min.js');
        wp_enqueue_script('prism-core-js', 'https://cdn.jsdelivr.net/npm/[email protected]/components/prism-core.min.js');
        wp_enqueue_style('prism-css', 'https://cdn.jsdelivr.net/npm/[email protected]/themes/prism.min.css');
        wp_enqueue_script('prism-autoloader-js', 'https://cdn.jsdelivr.net/npm/[email protected]/plugins/autoloader/prism-autoloader.min.js');
    }
}
add_action('wp_enqueue_scripts', 'code_pre_theme', 10); //Number 10 heres depend on site. The princlple is to set a number larger than the essential scripts and styles belong to your parent theme, which is vantage in this case.

By enqueuing prism-core.min.js and prism-autoloader.min.js, it will utomatically loads languages's style when necessary.
You may opt-in languages based on your needs. For example, to load certain style based on has_tag('php'), has_tag('csharp') result.
Visit prism.js at cdnjs.com for more programming language supports.

Conlusion

You don't have to follow every steps as I did, as you may come up with a better solution for your own site.

At the time I wrote this article, I absolutely have zero knowledge in PHP, only knowing C#, Javascript, Java, SCSS; writing and modifying some php script isn't complicated, so go ahead and try all the possibilities.

趨勢科技 ServerProtect 密碼重設


layout: post
title: 趨勢科技 ServerProtect 密碼重設
date: 2021-09-15 15:02 +8
description: 密碼重設方法
toc: false
share: true
comments: true
tags: Windows TrendMicro AntiVirus

注意

本文為 Windows 平台運行 ServerProtect 的密碼重設方法,請務必詳細閱讀下列內容,並且自行檢查是否符合您的需求。

解決方法

  1. 開啟 regedit 登錄編輯程式
    若 OS 為 64 位元,循 HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\ServerProtect\CurrentVersion\Agent
    若OS 為 32 位元,循 HKEY_LOCAL_MACHINE\SOFTWARE\TrendMicro\ServerProtect\CurrentVersion\Agent
  2. 將其 AgentPassword 的值刪除。
  3. 這樣密碼即會變更為預設密碼:VPROTECT

心得

這種密碼系統也太脆弱吧!
這樣豈不任何人都可恣意 Bypass 密碼驗證了嗎?

參考資料

Windows IIS 8 網站莫名 403.3 驗證錯誤


layout: post
title: Windows IIS 8 網站莫名 403.3 驗證錯誤
date: 2021-09-15 11:49 +8
description: Windows 資料夾權限調整。
toc: false
share: true
comments: true
tags: IIS Windows

注意

本文為 Windows 的 IIS 8 及更新版本的解決方案。

檢查問題

  1. 創建一個新的網站,並建立簡單的 helloWorld.html 檔案,如果是在子目錄,記得要轉成「網站應用程式」。
  2. 該資料夾權限給予 Everyone 權限「Full Control」。
  3. 若如此能解決問題,則確立為權限設定問題。

主要解決方法

  1. 在 wwwroot 或是該網站根目錄,給予 IIS_IUSRS 群組 Read 和 Write 權限。
  2. 執行命令 iisreset /restart,這將重新啟動 IIS,以讓新權限設定生效。
  3. 在不同電腦上,瀏覽剛剛設定的網站,檢查是否可以正常顯示。若不行,則採取替代方法如下。

替代解決方法

  1. 在 wwwroot 或是該網站根目錄,給予 IIS AppPool\MyApplicationPoolName 群組 Read 和 Write 權限。
    ※此處 MyApplicationPoolName 應該是該網站的應用程式池名稱。
  2. 切換至 Internet Information Services (IIS) Manager,點選該網站。
  3. 右側面板點選 IIS 分類底下的 "Authentication"。
  4. 在 "Authentication" 下面的 "Anoymous Authentication" 選項,確保為 "Enable"。
  5. 對其點右鍵,選擇 "Edit..."。
  6. 預設選項應該為 "Specific user": "IUsr",我們切換為第二項 "Application pool identity"。
  7. 執行命令 iisreset /restart,這將重新啟動 IIS,以讓新權限設定生效。
  8. 在不同電腦上,瀏覽剛剛設定的網站,檢查是否可以正常顯示。我到這邊就解決問題了。

參考資料

利用 Google Maps Javascript 匯入 KML 檔案自動畫圖


layout: post
title: 利用 Google Maps Javascript 匯入 KML 檔案自動畫圖
date: 2021-08-24 17:41 +8
description: 如何不自己讀取資料,直接利用 KmlLayer 呈現。以及可能會碰到的問題。
toc: false
share: true
comments: true
tags: GoogleMaps Javascript Development

程式碼

可能問題

線條粗細和在 Google My Maps 或 Google Earth 上看到的不一樣! 怎麼變那麼粗?

需要手動在 KML 檔案中,自行針對每項 <LineStyle></LineStyle> 加入 <width>0.001</width>
0.001 可自行改成所需的值。
Tip: 尋找與取代 </LineStyle><width>0.001</width></LineStyle>

個人向 Jekyll 的各種狀況


layout: post
title: Jekyll tips
date: 2021-08-21 17:41 +8
description: 個人向 Jekyll 的各種狀況
toc: false
share: true
comments: true
tags: Jekyll Development

編譯問題

ffi-1.11.1-x64-mingw32 requires ruby version < 2.7.dev, >= 2.2, which is incompatible with the current version, ruby 2.7.4p191
我 2019 年使用 Ruby 2.5,2021 年我換到另一台電腦並且改用 Ruby 2.7.4,結果原本專案執行 bundle exec jekyll serve 無法部署。

解法: 運行 bundle update 看能否解決問題