feat: follow site locale for typography
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
/* MING 明命 — 自托管字体(v1.5.6 起替代 Google Fonts 外链)
|
||||
来源:google/fonts(OFL 授权),经子集化(Big5 常用字 + 全形标点)与字重实例化 */
|
||||
/* MING 明命 — 自托管字體(v1.5.6 起替代 Google Fonts 外鏈)
|
||||
繁體中文站點使用下列 TC 字型;其他站點語言由主題選用對應系統字型。
|
||||
來源:google/fonts(OFL 授權),經子集化(Big5 常用字 + 全形標點)與字重實例化。 */
|
||||
|
||||
@font-face {
|
||||
font-family: 'Cormorant Garamond';
|
||||
|
||||
@@ -8,9 +8,10 @@
|
||||
--ink:#2B2B26;
|
||||
--muted:#7A756A;
|
||||
--line:rgba(43,43,38,.16);
|
||||
--serif:'Noto Serif TC',serif;
|
||||
--latin:'Cormorant Garamond','Noto Serif TC',serif;
|
||||
--sans:'Noto Sans TC',sans-serif;
|
||||
/* WordPress 依站點語言於前台覆寫下列字型堆疊。 */
|
||||
--serif:Georgia,'Times New Roman',serif;
|
||||
--latin:'Cormorant Garamond',Georgia,'Times New Roman',serif;
|
||||
--sans:system-ui,-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;
|
||||
}
|
||||
*{margin:0;padding:0;box-sizing:border-box}
|
||||
html{scroll-behavior:smooth}
|
||||
|
||||
@@ -39,7 +39,7 @@ $ming_mailto = $ming_email ? $ming_email : 'hello@ming.example';
|
||||
<?php endif; ?>
|
||||
<?php if ( $ming_line ) : ?>
|
||||
<a href="<?php echo esc_url( $ming_line ); ?>" target="_blank" rel="noopener" aria-label="LINE" title="LINE">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M12 4C7 4 3 6.9 3 10.6c0 3.3 2.9 6 6.8 6.6.3.1.7.2.8.5.1.2.1.6 0 .9l-.4 1.3c0 .2-.1.6.5.4.6-.3 3.3-2 4.5-2.7 2.9-1.3 4.8-3.6 4.8-7C21 6.9 17 4 12 4z"/><text x="12" y="13" text-anchor="middle" font-size="5.2" font-weight="600" fill="currentColor" stroke="none" font-family="sans-serif" letter-spacing=".5">LINE</text></svg>
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" style="font-family:var(--sans)"><path d="M12 4C7 4 3 6.9 3 10.6c0 3.3 2.9 6 6.8 6.6.3.1.7.2.1.6 0 .9l-.4 1.3c0 .2-.1.6.5.4.6-.3 3.3-2 4.5-2.7 2.9-1.3 4.8-3.6 4.8-7C21 6.9 17 4 12 4z"/><text x="12" y="13" text-anchor="middle" font-size="5.2" font-weight="600" fill="currentColor" stroke="none" letter-spacing=".5">LINE</text></svg>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
+114
-2
@@ -9,7 +9,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
define( 'MING_VERSION', '1.7.3' );
|
||||
define( 'MING_VERSION', '1.7.4' );
|
||||
|
||||
/**
|
||||
* Theme setup.
|
||||
@@ -52,6 +52,66 @@ function ming_setup() {
|
||||
}
|
||||
add_action( 'after_setup_theme', 'ming_setup' );
|
||||
|
||||
/**
|
||||
* Return the site's WordPress locale in a form suitable for comparisons.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function ming_site_locale() {
|
||||
return strtolower( str_replace( '-', '_', get_locale() ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Build font stacks for the language selected in WordPress settings.
|
||||
*
|
||||
* Self-hosted TC font files are used for Traditional Chinese. Other site
|
||||
* languages use the appropriate platform font stack and do not request a
|
||||
* Chinese Traditional web font.
|
||||
*
|
||||
* @return string CSS custom-property declarations.
|
||||
*/
|
||||
function ming_font_stack_css() {
|
||||
$locale = ming_site_locale();
|
||||
$fonts = array(
|
||||
'sans' => "system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif",
|
||||
'serif' => "Georgia, 'Times New Roman', serif",
|
||||
'latin' => "'Cormorant Garamond', Georgia, 'Times New Roman', serif",
|
||||
);
|
||||
|
||||
if ( preg_match( '/^zh_(?:hant(?:_|$)|tw(?:_|$)|hk(?:_|$)|mo(?:_|$))/', $locale ) ) {
|
||||
$fonts = array(
|
||||
'sans' => "'Noto Sans TC', 'Noto Sans CJK TC', 'PingFang TC', 'Microsoft JhengHei', 'Heiti TC', sans-serif",
|
||||
'serif' => "'Noto Serif TC', 'Noto Serif CJK TC', 'Songti TC', 'PMingLiU', 'MingLiU', serif",
|
||||
'latin' => "'Cormorant Garamond', 'Noto Serif TC', 'Noto Serif CJK TC', 'Songti TC', serif",
|
||||
);
|
||||
} elseif ( preg_match( '/^zh_/', $locale ) ) {
|
||||
$fonts = array(
|
||||
'sans' => "'Noto Sans SC', 'Noto Sans CJK SC', 'PingFang SC', 'Microsoft YaHei', 'Heiti SC', sans-serif",
|
||||
'serif' => "'Noto Serif SC', 'Noto Serif CJK SC', 'Songti SC', SimSun, serif",
|
||||
'latin' => "'Cormorant Garamond', 'Noto Serif SC', 'Noto Serif CJK SC', 'Songti SC', serif",
|
||||
);
|
||||
} elseif ( preg_match( '/^ja(?:_|$)/', $locale ) ) {
|
||||
$fonts = array(
|
||||
'sans' => "'Noto Sans JP', 'Hiragino Kaku Gothic ProN', 'Yu Gothic', Meiryo, sans-serif",
|
||||
'serif' => "'Noto Serif JP', 'Hiragino Mincho ProN', 'Yu Mincho', serif",
|
||||
'latin' => "'Cormorant Garamond', 'Noto Serif JP', 'Hiragino Mincho ProN', serif",
|
||||
);
|
||||
} elseif ( preg_match( '/^ko(?:_|$)/', $locale ) ) {
|
||||
$fonts = array(
|
||||
'sans' => "'Noto Sans KR', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif",
|
||||
'serif' => "'Noto Serif KR', AppleMyungjo, Batang, serif",
|
||||
'latin' => "'Cormorant Garamond', 'Noto Serif KR', AppleMyungjo, serif",
|
||||
);
|
||||
}
|
||||
|
||||
return sprintf(
|
||||
":root {\n\t--serif: %1\$s;\n\t--latin: %2\$s;\n\t--sans: %3\$s;\n}\n",
|
||||
$fonts['serif'],
|
||||
$fonts['latin'],
|
||||
$fonts['sans']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue assets.
|
||||
*/
|
||||
@@ -65,6 +125,7 @@ function ming_assets() {
|
||||
);
|
||||
|
||||
wp_enqueue_style( 'ming-main', get_template_directory_uri() . '/assets/css/main.css', array( 'ming-fonts' ), MING_VERSION );
|
||||
wp_add_inline_style( 'ming-main', ming_font_stack_css() );
|
||||
wp_enqueue_script( 'ming-main', get_template_directory_uri() . '/assets/js/main.js', array(), MING_VERSION, true );
|
||||
|
||||
// Pass image directory to JS (product grid).
|
||||
@@ -734,6 +795,57 @@ add_action( 'after_switch_theme', 'ming_seed_footer_content' );
|
||||
* ==========================================================*/
|
||||
|
||||
/* ---------- OG / Twitter 分享標籤 ---------- */
|
||||
/**
|
||||
* Return an Open Graph locale derived from the WordPress site language.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function ming_og_locale() {
|
||||
$locale = ming_site_locale();
|
||||
|
||||
if ( 0 === strpos( $locale, 'zh_' ) ) {
|
||||
if ( preg_match( '/(?:hk)/', $locale ) ) {
|
||||
return 'zh_HK';
|
||||
}
|
||||
if ( preg_match( '/(?:mo)/', $locale ) ) {
|
||||
return 'zh_MO';
|
||||
}
|
||||
|
||||
return preg_match( '/(?:hant|tw)/', $locale ) ? 'zh_TW' : 'zh_CN';
|
||||
}
|
||||
|
||||
$parts = explode( '_', $locale );
|
||||
$language = isset( $parts[0] ) ? $parts[0] : 'en';
|
||||
$region = '';
|
||||
foreach ( array_reverse( $parts ) as $part ) {
|
||||
if ( 2 === strlen( $part ) && ctype_alpha( $part ) ) {
|
||||
$region = strtoupper( $part );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $region ) {
|
||||
return $language . '_' . $region;
|
||||
}
|
||||
|
||||
$default_regions = array(
|
||||
'ar' => 'SA',
|
||||
'de' => 'DE',
|
||||
'en' => 'US',
|
||||
'es' => 'ES',
|
||||
'fr' => 'FR',
|
||||
'it' => 'IT',
|
||||
'ja' => 'JP',
|
||||
'ko' => 'KR',
|
||||
'nl' => 'NL',
|
||||
'pl' => 'PL',
|
||||
'pt' => 'BR',
|
||||
'ru' => 'RU',
|
||||
);
|
||||
|
||||
return isset( $default_regions[ $language ] ) ? $language . '_' . $default_regions[ $language ] : 'en_US';
|
||||
}
|
||||
|
||||
add_action( 'wp_head', 'ming_og_tags', 5 );
|
||||
function ming_og_tags() {
|
||||
if ( is_admin() || ( function_exists( 'is_embed' ) && is_embed() ) ) { return; }
|
||||
@@ -779,7 +891,7 @@ function ming_og_tags() {
|
||||
echo '<meta property="og:description" content="' . esc_attr( $desc ) . '">' . "\n";
|
||||
echo '<meta property="og:url" content="' . esc_url( $url ) . '">' . "\n";
|
||||
echo '<meta property="og:type" content="' . esc_attr( $type ) . '">' . "\n";
|
||||
echo '<meta property="og:locale" content="zh_TW">' . "\n";
|
||||
echo '<meta property="og:locale" content="' . esc_attr( ming_og_locale() ) . '">' . "\n";
|
||||
if ( $image ) {
|
||||
echo '<meta property="og:image" content="' . esc_url( $image ) . '">' . "\n";
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ Theme URI: https://ming.example
|
||||
Author: MING 明命
|
||||
Author URI: https://ming.example
|
||||
Description: MING 明命品牌官網主題 —— 陶瓷內膽杯 · 明亮生命 自然連結。單頁式品牌首頁,支援 WooCommerce 商城、會員中心、購物車角標、社群連結與公司資訊自訂。
|
||||
Version: 1.7.3
|
||||
Version: 1.7.4
|
||||
Requires at least: 6.0
|
||||
Tested up to: 6.7
|
||||
Requires PHP: 7.4
|
||||
|
||||
@@ -65,7 +65,7 @@ get_header();
|
||||
<h3>太陽與光</h3><p>光明溫暖,<br>希望明亮。</p>
|
||||
</div>
|
||||
<div class="symbol">
|
||||
<svg viewBox="0 0 64 64"><circle cx="32" cy="32" r="22"/><text x="32" y="28" text-anchor="middle" font-size="15" fill="var(--green)" stroke="none" font-family="'Noto Serif TC',serif">明</text><text x="32" y="48" text-anchor="middle" font-size="15" fill="var(--green)" stroke="none" font-family="'Noto Serif TC',serif">命</text></svg>
|
||||
<svg viewBox="0 0 64 64" style="font-family:var(--serif)"><circle cx="32" cy="32" r="22"/><text x="32" y="28" text-anchor="middle" font-size="15" fill="var(--green)" stroke="none">明</text><text x="32" y="48" text-anchor="middle" font-size="15" fill="var(--green)" stroke="none">命</text></svg>
|
||||
<h3>明・命</h3><p>生命因光而明,<br>萬物因自然而生。</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user