「モジュール:YouTube channel」の版間の差分
ナビゲーションに移動
検索に移動
細 (Softyu がページ「モジュール:YouTube channe」を「モジュール:YouTube channel」に、リダイレクトを残さずに移動しました: 误字) |
編集の要約なし |
||
25行目: | 25行目: | ||
function p.main( frame ) | function p.main( frame ) | ||
local args = require( 'Module:Arguments' ).getArgs( frame, { wrappers = 'Template: | local args = require( 'Module:Arguments' ).getArgs( frame, { wrappers = 'Template:YouTube_channel', removeBlanks = false, parentFirst = true }); | ||
local dataStore = {} | local dataStore = {} | ||
-- | -- YouTube_channel ID | ||
local y_id = args[1] or args.id or ''; | local y_id = args[1] or args.id or ''; | ||
local formatterURL = "https://www.youtube.com/channel/$1"; | local formatterURL = "https://www.youtube.com/channel/$1"; | ||
44行目: | 44行目: | ||
end | end | ||
-- | -- YouTube_channel 表示名 | ||
local name = args[2] or args.name or ''; | local name = args[2] or args.name or ''; | ||
53行目: | 53行目: | ||
-- | -- YouTube_channel 表示名デフォルト | ||
if name == '' then | if name == '' then | ||
name = "YouTube チャンネル"; | name = "YouTube チャンネル"; |
2020年3月21日 (土) 13:55時点における版
このモジュールについての説明文ページを モジュール:YouTube channel/doc に作成できます
local p = {};
local function setProperty(dataStore)
-- メイン空間のみ
if not mw.title.getCurrentTitle().namespace == 0 then
return true;
end
if not mw.smw then
return true;
end
local result = mw.smw.set(dataStore)
if result == true then
-- everything ok
else
-- error message to be found in result.error
end
end
function p.main( frame )
local args = require( 'Module:Arguments' ).getArgs( frame, { wrappers = 'Template:YouTube_channel', removeBlanks = false, parentFirst = true });
local dataStore = {}
-- YouTube_channel ID
local y_id = args[1] or args.id or '';
local formatterURL = "https://www.youtube.com/channel/$1";
local url = mw.ustring.gsub(formatterURL, "\$1", y_id);
dataStore['YouTubeチャンネル'] = y_id
-- YouTube_user ID
if args.user then
local y_user = args.user or '';
formatterURL = "https://www.youtube.com/user/$1";
url = mw.ustring.gsub(formatterURL, "\$1", y_user);
dataStore['YouTubeユーザー'] = y_user
end
-- YouTube_channel 表示名
local name = args[2] or args.name or '';
-- SemanticMediaWiki
if not args.smw then
setProperty(dataStore);
end
-- YouTube_channel 表示名デフォルト
if name == '' then
name = "YouTube チャンネル";
end
return '[' ..url ..' ' ..name ..'] - [[YouTube]]';
end
return p;