Posted on 2018/11/12 00:02:20 in: お知らせ | Post Comment
春ごろにさくらのレンタルサーバが新構成に更新されたというころで、さくらのスタンダードからさくらのスタンダードへ移転しました。
とても快適(*´д`*) WordPress管理画面の体感では5倍以上速い。ついでにhttpsにしました。
旧環境は、最初は静的HTMLと掲示板CGI、後にBlosxom、ファイル操作をミスって日付がおかしくなったあたりからWordPressを使うようになりました。
この環境でWordPressを使うにはなかなか重荷で、PHP5.6未満の頃はAPCuとかOPcacheを別途makeしてみたり(CGIモードだったので効果無かったのですが…)キャッシュプラグインをあれこれ入れてみてなんとか凌いでました。
2004年から14年間、趣味にお仕事に支えていただいた旧環境、本当にありがとうございました。
これからも新環境でどうぞよろしくお願いいたします。
Posted on 2018/07/31 11:45:47 in: ネタ | Post Comment
目的
源ノ明朝をウェブフォントとして利用したいけどハイパー重いので、ひらがな・カタカナ・よく使う英数記号・常用漢字だけを抜き取って書き出したい。
下準備
あらかじめPythonがインストールされている環境で(MacだとHomebrewで入れるのが良さそう)、fonttools と brotli をインストール。
> pip install fonttools brotli
作業
以下の例は源ノ明朝のサブセットを作る流れです。
- 最新フォントデータをダウンロードする
https://github.com/adobe-fonts/source-han-serif/tree/release/OTF/Japanese - 収録する文字を用意する。例) subset_joyo.txt
- 各ファイルを適当なディレクトリにまとめて、pyftsubsetに投下。
(以下は SourceHanSerif-Medium を SHS-M-joyo として書き出す例) > pyftsubset ./SourceHanSerif-Medium.otf --text-file=./subset_joyo.txt --layout-features='*' --flavor=woff --output-file=./SHS-M-joyo.woff
> pyftsubset ./SourceHanSerif-Medium.otf --text-file=./subset_joyo.txt --layout-features='*' --flavor=woff2 --output-file=./SHS-M-joyo.woff2
結果
概ね現実的なサイズまで小さくなりました。
- woff : 1.7MB
- woff2 : 1.4MB
この記事の続きを見る »
Posted on 2018/05/11 11:10:50 in: ネタ | Post Comment
(追記) Prime Videoで動かないなーと思ったら name=”itemId” だったのでセレクタを追加しました。
(追記2) またもやPrime Videoで動かないのでセレクタを追加しました。
手垢が付きまくった小ネタ。
最初、URLを分解して抜き出すみたいなことをやってたのですが、ページ内のフォーム要素に記載されているようなのでそちらを利用することにします。
PCやスマホ画面を眺めてみると、商品コードが収まる <input type=”hidden”> 要素のnameが ASIN.0 とか ASIN とか asin などまちまちだったので、document.querySelector に全てのセレクタをつっこんで、見つかったものを摘めばシンプルでよかろうと思いました。
javascript:!function(){var e,t=document.querySelector("[data-title-id]"),a=document.querySelector('[name="ASIN.0"],[name="ASIN"],[name="asin"],[name="itemId"]');t&&(e=t.getAttribute("data-title-id")),a&&(e=a.value),e&&(location.href="https://www.amazon.co.jp/dp/"+e)}();
上のブックマークレットは、以下のコードをJavaScript Minifierに通しました。
(function(){
var asin,
dtid_elm = document.querySelector('[data-title-id]'),
asin_elm = document.querySelector('[name="ASIN.0"],[name="ASIN"],[name="asin"],[name="itemId"]');
if ( dtid_elm ) asin = dtid_elm.getAttribute('data-title-id');
if ( asin_elm ) asin = asin_elm.value;
if ( id ) location.href = 'https://www.amazon.co.jp/dp/' + asin;
})();
Posted on 2018/01/04 01:38:54 in: 備忘録 | Post Comment

今年も先人の文字を参考に書き初め。
Posted on 2017/06/01 23:06:06 in: 備忘録 | Post Comment
追記 20180416
最近のChromeのバージョンでは、以下サイトの方法が最良です。
必要な時はしばらくこんな具合で使ってみます。
font-family: "游ゴシック Medium", "Yu Gothic Medium", "游ゴシック体", YuGothic, "Hiragino Kaku Gothic ProN", "ヒラギノ角ゴ Pro W3", Meiryo, Verdana, sans-serif;
※ここから下は現在参考になりませんのでご留意ください。
参考サイト
以外と厄介なんですね…
妥協案
@font-face {
font-family: "Yu Gothic";
src: local("Yu Gothic Medium"),local("Yu Gothic");
font-weight: 500;
}
@font-face {
font-family: "Yu Gothic";
src: local("Yu Gothic Bold"),local("Yu Gothic");
font-weight: bold;
}
body {
font-family: "Yu Gothic", YuGothic, sans-serif;
}
たまにこんな塩梅で使っています。
body {
font-family: "Yu Gothic", YuGothic, "Lucida Grande", "Hiragino Kaku Gothic ProN", "ヒラギノ角ゴ Pro W3", "メイリオ", Meiryo, Osaka, Verdana, sans-serif;
font-feature-settings: 'pkna';
letter-spacing: 0.5px;
}
比較画像を作ってみました。
游ゴシックは16px未満だと本文書体としては厳しそう。
Posted on 2017/01/03 15:06:48 in: 備忘録 | Post Comment

明代の文人、文徴明氏の「酉」をお手本にしました。
Posted on 2016/12/23 21:17:25 in: WordPress | Post Comment
一律に拒否してしまうと会社等のプロキシからも書き込めなくなってしまうので、一旦承認待ちとなるようにしています。
先にAkismet等がspamとしたものは尊重するようにし、そうならなかったコメントを判定対象とします。
プロキシ特有の環境変数は HTTP_X_FORWARDED_FOR や HTTP_VIA を見れば良いっぽいですが、必要に応じて足してみてください。
※textbox.jpでは使っていません。
テーマの functions.php に追記する内容
add_action( 'comment_post', 'proxy_comment_unapproved', 15, 1 );
function proxy_comment_unapproved( $comment_ID ) {
if ( !empty($_SERVER['HTTP_X_FORWARDED_FOR']) || !empty($_SERVER['HTTP_VIA']) ) {
$comment = get_comment( $comment_ID );
$comment_arr = array();
$comment_arr['comment_ID'] = $comment_ID;
if ( $comment->comment_approved !== 'spam' ) {
$comment_arr['comment_approved'] = 0;
}
wp_update_comment( $comment_arr );
}
}
参考:Function Reference/wp update comment
もうちょっと頑張るならば、例えばTorの出口ノードリストを定期的に取得して保存しておき、投稿者のIPアドレスがそれに含まれるか判定する条件分岐を追加しても良いかもしれません。
Posted on 2016/08/18 12:32:24 in: WordPress | Post Comment
使う頻度がわりとあるのでメモとして。(ちょいちょい修正・追記しています)
global $post;
$url = get_permalink($post->ID);
$enc_url = rawurlencode($url);
$title = get_the_title($post->ID) . ' | (短めのサイト名)';
$enc_title = rawurlencode($title);
$thumbnail = get_the_post_thumbnail_url($post->ID,'large');
$enc_thumbnail = rawurlencode($thumbnail);
$link_twitter = 'http://twitter.com/intent/tweet?text='.$enc_title.'&url='.$enc_url;
$link_facebook = 'http://www.facebook.com/sharer.php?u='.$enc_url;
$link_hatena = 'http://b.hatena.ne.jp/entry/'.$enc_url;
$link_line = 'http://line.me/R/msg/text/?'.$enc_title.'%20'.$enc_url;
$link_pinterest = 'http://www.pinterest.com/pin/create/button/?url='.$enc_url.'&media='.$enc_thumbnail.'&description='.$enc_url;
Posted on 2016/08/18 12:24:38 in: WordPress | Post Comment
指定期間を過ぎたらリンクタグのみ除外したい、という要望があったので作ってみた小ネタ。
キャッシュプラグインやnginxでページキャッシュを有効にしている場合は、取下げ時刻にキャッシュクリアする必要があるのでご注意ください。
■使用例
*中のテキストもまるごと取り下げたい
[limit_link href="http://www.google.com" end="2016-03-05 01:51:00"]サンプルテキスト[/limit_text]
*リンクだけ取り下げたい+別ウィンドウで開く
[limit_link href="http://www.google.com" end="2016-03-05 01:51:00" target="_blank" text="show"]サンプルテキスト[/limit_link]
function custom_shortcode_limit_link( $atts, $content = null ) {
extract( shortcode_atts( array(
'href' => 'http://example.com/',
'target' => '_self',
'end' => '2015-12-31 23:59:59',
'text' => 'hide'
), $atts ) );
$now = date_i18n('U'); // 現在の時刻
$expire_date = date('U',strtotime($end)); // 取り下げ時刻
if($expire_date >= $now) {
// リンク掲出期間中
return '<a href="' . esc_html($href) . '" target="' . esc_html($target) . '">' . esc_html($content) . '</a>';
} elseif ($text === 'show') {
// 掲出終了後、テキストは表示する場合
return esc_html($content);
} else {
// 掲出終了後、丸ごと消す場合
return;
}
}
add_shortcode('limit_link', 'custom_shortcode_limit_link');
Posted on 2016/01/24 01:04:50 in: WordPress | Post Comment
function media_upload_default( $post_ID ) {
$args = array(
'ID' => $post_ID,
'post_title' => '',
'post_excerpt' => '',
'post_content' => '',
);
wp_update_post( $args );
}
add_action( 'add_attachment', 'media_upload_default' );
下記サイトを参考にしました。
How can I add a default description to uploaded files?
http://wordpress.stackexchange.com/questions/121709/how-can-i-add-a-default-description-to-uploaded-files