Skip to content

Commit

Permalink
Merge pull request #17 from igapyon/feature_20170121a
Browse files Browse the repository at this point in the history
Feature 20170121a
  • Loading branch information
igapyon authored Jan 22, 2017
2 parents ecd6a84 + 000021e commit 4986f0b
Show file tree
Hide file tree
Showing 18 changed files with 134 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,20 @@ public void processDir() throws IOException {
// 日記ファイルの新規作成に移ります。

final List<String> lines = new ArrayList<String>();
lines.add("## ここに日記のタイトル");
lines.add("## ここにコンテンツのタイトル");
lines.add("");
lines.add("ここに何か日記の内容。");
lines.add("ここに何か内容。");
lines.add("");
lines.add("* 箇条書き1");
lines.add("* 箇条書き2");
lines.add(" * 箇条書き2-1");
lines.add("");
lines.add("```java:Hello.java");
lines.add("```java");
lines.add("System.out.println(\"Hello world\");");
lines.add("```");
lines.add("");
lines.add("<#-- copyright " + settings.getAuthor() + " -->");
lines.add("<@linkshare word=\"本日の日記。ここに日記タイトルが入ってほしい。\"/>");

// 日記ファイルを新規作成します。
FileUtils.writeLines(file, lines);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void process() throws IOException {
Collections.sort(diaryItemInfoList, new DiaryItemInfoComparator(true));

SimpleRomeUtil.itemList2AtomXml(diaryItemInfoList, new File(settings.getRootdir(), "atom.xml"),
"Igapyon Diary v3 all", settings);
settings.getTitleEn() + " all", settings);

{
int diaryListupCount = 15;
Expand All @@ -96,7 +96,7 @@ public void process() throws IOException {
Collections.sort(diaryItemInfoList, new DiaryItemInfoComparator(true));

SimpleRomeUtil.itemList2AtomXml(recentItemInfoList, new File(settings.getRootdir(), "atomRecent.xml"),
"Igapyon Diary v3 recent", settings);
settings.getTitleEn() + " recent", settings);
}
}

Expand Down Expand Up @@ -136,7 +136,7 @@ public boolean isProcessTarget(final File file) {
Collections.sort(diaryItemInfoList, new DiaryItemInfoComparator(true));

SimpleRomeUtil.itemList2AtomXml(diaryItemInfoList, new File(settings.getRootdir(), year + "/atom.xml"),
"Igapyon Diary v3 year " + year, settings);
settings.getTitleEn() + " year " + year, settings);
}

{
Expand All @@ -151,7 +151,7 @@ public boolean isProcessTarget(final File file) {
Collections.sort(diaryItemInfoList, new DiaryItemInfoComparator(false));

SimpleRomeUtil.itemList2AtomXml(diaryItemInfoList, new File(settings.getRootdir(), "memo" + "/atom.xml"),
"Igapyon Diary v3 memo", settings);
settings.getTitleEn() + " memo", settings);
}

{
Expand All @@ -163,7 +163,7 @@ public boolean isProcessTarget(final File file) {
Collections.sort(diaryItemInfoList, new DiaryItemInfoComparator(false));

SimpleRomeUtil.itemList2AtomXml(diaryItemInfoList, new File(settings.getRootdir(), "keyword" + "/atom.xml"),
"Igapyon Diary v3 keyword", settings);
settings.getTitleEn() + " keyword", settings);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void generateNewKeyword() throws IOException {
}

final List<String> lines = new ArrayList<String>();
lines.add("[index](https://igapyon.github.io/diary/keyword/index.html)");
lines.add("[index](" + settings.getBaseurl() + "/keyword/index.html)");
lines.add("");
lines.add("## " + word + "");
lines.add("");
Expand All @@ -145,8 +145,8 @@ public void generateNewKeyword() throws IOException {
lines.add("");
lines.add("### 検索");
lines.add("");
lines.add("* <@linksearch title=\"Search on Igapyon Diary\" word=\"" + word
+ "\" site=\"https://igapyon.github.io/diary/\" />");
lines.add("* <@linksearch title=\"Search on " + settings.getTitleEn() + "\" word=\"" + word
+ "\" site=\"" + settings.getBaseurl() + "/\" />");
lines.add("* <@linksearch title=\"Search in Google\" word=\"" + word + "\" />");
lines.add("* <@linksearch title=\"Search in Twitter\" word=\"" + word
+ "\" engine=\"twitter\" />");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ void processFile(final File file) throws IOException {
lines.set(index, line);
}

// TODO .src.md から .md を取得するための共通関数がほしいです。
String newName = file.getName().substring(0, file.getName().length() - (".src.md".length())) + ".md";
FileUtils.writeLines(new File(file.getParentFile(), newName), lines);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ public static String process(File file, final Map<String, Object> templateData,

final Configuration config = getConfiguration(settings, true);

// set settings obj
templateData.put("settings", settings);

final Template templateBase = config.getTemplate(relativePath);
try {
final StringWriter writer = new StringWriter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@

import freemarker.cache.TemplateLoader;
import jp.igapyon.diary.v3.util.IgapyonV3Settings;
import jp.igapyon.diary.v3.util.SimpleDirUtil;

/**
* igapyonv3 向けの所定の挙動をおこなうテンプロードローダーです。
Expand Down Expand Up @@ -211,6 +212,7 @@ public Object findTemplateSource(final String resourceName) throws IOException {
}

if (actualFile.getName().startsWith("ig") && false == actualFile.getName().startsWith("iga")) {
// 日記ノードの処理。
String year1 = "20";
String year2 = actualFile.getName().substring(2, 4);
if (year2.startsWith("9")) {
Expand Down Expand Up @@ -248,10 +250,23 @@ public Object findTemplateSource(final String resourceName) throws IOException {

// ヘッダ追加
header += (year1 + year2 + "-" + month + "-" + day + " diary: " + firstH2Line + "\n");
header += "=====================================================================================================\n";
header += "[![いがぴょん画像(小)](" + settings.getBaseurl() + "/images/iga200306s.jpg \"いがぴょん\")]("
+ settings.getBaseurl() + "/memo/memoigapyon.html) 日記形式でつづる [いがぴょん](" + settings.getBaseurl()
+ "/memo/memoigapyon.html)コラム ウェブページです。\n";

{
// TODO 一行目の展開ができていません。良い実装方法を考えましょう。
final File fileTemplate = new File(settings.getRootdir(), "template-header.md");
if (fileTemplate.exists()) {
final String template = FileUtils.readFileToString(fileTemplate, "UTF-8");
header += template;
if (header.endsWith("\n") == false) {
header += "\n";
}
} else {
System.err.println("template-header.md not found.:" + fileTemplate.getCanonicalPath());
header += "===================================\n";
header += "<#-- template-header.md not found. -->\n";
}
}

header += "\n";

load = header + load;
Expand Down Expand Up @@ -321,25 +336,45 @@ public Object findTemplateSource(final String resourceName) throws IOException {
}

footer += "\n";
footer += "----------------------------------------------------------------------------------------------------\n";
footer += "\n";
footer += "## この日記について\n";
footer += "[いがぴょんについて](" + settings.getBaseurl()
+ "/memo/memoigapyon.html) / [日記ジェネレータ](https://github.com/igapyon/igapyonv3)\n";

{
final File fileTemplate = new File(settings.getRootdir(), "template-footer.md");
if (fileTemplate.exists()) {
final String template = FileUtils.readFileToString(fileTemplate, "UTF-8");
footer += template;
} else {
System.err.println("template-footer.md not found.:" + fileTemplate.getCanonicalPath());
}
}

load += footer;
} else {
} else if (actualFile.getName().startsWith("index") || actualFile.getName().startsWith("idxall")
|| actualFile.getName().startsWith("README") || actualFile.getName().startsWith("memo")
|| SimpleDirUtil.getRelativePath(settings.getRootdir(), actualFile).startsWith("keyword")) {
final String firstH2Line = getFirstH2String(actualFile);

String header = "[top](" + settings.getBaseurl() + "/) \n";
header += "\n";

// ヘッダ追加
header += (firstH2Line + "\n");
header += "=====================================================================================================\n";
header += "[![いがぴょん画像(小)](" + settings.getBaseurl() + "/images/iga200306s.jpg \"いがぴょん\")]("
+ settings.getBaseurl() + "/memo/memoigapyon.html) 日記形式でつづる [いがぴょん](" + settings.getBaseurl()
+ "/memo/memoigapyon.html)コラム ウェブページです。\n";

{
// TODO 一行目の展開ができていません。良い実装方法を考えましょう。
final File fileTemplate = new File(settings.getRootdir(), "template-header.md");
if (fileTemplate.exists()) {
final String template = FileUtils.readFileToString(fileTemplate, "UTF-8");
header += template;
if (header.endsWith("\n") == false) {
header += "\n";
}
} else {
System.err.println("template-header.md not found.:" + fileTemplate.getCanonicalPath());
header += "===================================\n";
header += "<#-- template-header.md not found. -->\n";
}
}

header += "\n";

load = header + load;
Expand Down Expand Up @@ -368,13 +403,23 @@ public Object findTemplateSource(final String resourceName) throws IOException {
}

footer += "\n";
footer += "----------------------------------------------------------------------------------------------------\n";
footer += "\n";
footer += "## この日記について\n";
footer += "[いがぴょんについて](" + settings.getBaseurl()
+ "/memo/memoigapyon.html) / [日記ジェネレータ](https://github.com/igapyon/igapyonv3)\n";

{
final File fileTemplate = new File(settings.getRootdir(), "template-footer.md");
if (fileTemplate.exists()) {
final String template = FileUtils.readFileToString(fileTemplate, "UTF-8");
footer += template;
} else {
System.err.println("template-footer.md not found.:" + fileTemplate.getCanonicalPath());
}
}

load += footer;
} else {
// TODO そのうちに、どのように判断するのか検討。
// 加工無し出力。
resourceMap.put(resourceName, load);
return resourceName;
}

resourceMap.put(resourceName, load);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void execute(final Environment env, @SuppressWarnings("rawtypes") final M

for (Object lookup : synFeed.getEntries()) {
final SyndEntry entry = (SyndEntry) lookup;
cacheAtomMap.put(entry.getTitle().substring(0, 10), entry);
cacheAtomMap.put(entry.getTitle().substring(0, Math.min(10, entry.getTitle().length() - 1)), entry);
}
} catch (FeedException e) {
throw new IOException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
package jp.igapyon.diary.v3.mdconv.freemarker.directive;

import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.util.Map;

Expand All @@ -47,6 +48,7 @@
import freemarker.template.TemplateModel;
import freemarker.template.TemplateModelException;
import jp.igapyon.diary.v3.util.IgapyonV3Settings;
import jp.igapyon.diary.v3.util.SimpleDirUtil;

/**
* Twitter シェアへのリンク用のディレクティブモデル
Expand All @@ -67,27 +69,34 @@ public void execute(final Environment env, @SuppressWarnings("rawtypes") final M
final TemplateModel[] loopVars, final TemplateDirectiveBody body) throws TemplateException, IOException {
final BufferedWriter writer = new BufferedWriter(env.getOut());

if (params.get("url") == null) {
throw new TemplateModelException("url param is required.");
if (params.get("url") != null) {
throw new IOException("url not supported: " + env.getMainTemplate().getSourceName());
}

if (params.get("word") == null) {
throw new TemplateModelException("word param is required.");
}

final String sourceName = env.getMainTemplate().getSourceName();
String urlString = SimpleDirUtil.file2Url(new File(settings.getRootdir(), sourceName), settings);
if (urlString.endsWith(".html.src.md")) {
urlString = urlString.substring(0, urlString.length() - ".src.md".length());
}

// SimpleScalar#toString()
final String urlString = params.get("url").toString();
final String wordString = params.get("word").toString();

String titleString = "Twitterでシェア";
String titleString = "Share on Twitter";
if (params.get("title") != null) {
titleString = params.get("title").toString();
}

String tagsString = "igapyon,diary";
String tagsString = "igapyon,diary,いがぴょん";
if (params.get("tags") != null) {
tagsString = params.get("tags").toString();
}

// Twitter以外のシェア方法は現状ありません。
// String engineString = "twitter";
// if (params.get("engine") != null) {
// engineString = params.get("engine").toString();
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/jp/igapyon/diary/v3/util/IgapyonV3Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ public class IgapyonV3Settings {
*/
private String language = "ja_JP";

/**
* 日記のタイトル。 主に atom で利用されます。
*/
private String titleEn = "Igapyon Diary v3";

/**
* Default double keywords.
*/
Expand Down Expand Up @@ -207,4 +212,12 @@ public String getBaseurl() {
public void setBaseurl(String baseurl) {
this.baseurl = baseurl;
}

public String getTitleEn() {
return titleEn;
}

public void setTitleEn(String titleEn) {
this.titleEn = titleEn;
}
}
11 changes: 0 additions & 11 deletions test/data/directive/localyearlist/test_localyearlist.html.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
[top](https://igapyon.github.io/diary/)

Test
=====================================================================================================
[![いがぴょん画像(小)](https://igapyon.github.io/diary/images/iga200306s.jpg "いがぴょん")](https://igapyon.github.io/diary/memo/memoigapyon.html) 日記形式でつづる [いがぴょん](https://igapyon.github.io/diary/memo/memoigapyon.html)コラム ウェブページです。

## Test

[2017](https://igapyon.github.io/diary/2017/index.html)
/ [ALL](https://igapyon.github.io/diary/idxall.html)


----------------------------------------------------------------------------------------------------

## この日記について
[いがぴょんについて](https://igapyon.github.io/diary/memo/memoigapyon.html) / [日記ジェネレータ](https://github.com/igapyon/igapyonv3)
13 changes: 6 additions & 7 deletions test/data/hatena/ig161226.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
/ [source](https://github.com/igapyon/diary/blob/gh-pages/2016/ig161226.html.src.md)

2016-12-26 diary: [maven] Title for test
=====================================================================================================
[![いがぴょん画像(小)](https://igapyon.github.io/diary/images/iga200306s.jpg "いがぴょん")](https://igapyon.github.io/diary/memo/memoigapyon.html) 日記形式でつづる [いがぴょん](https://igapyon.github.io/diary/memo/memoigapyon.html)コラム ウェブページです。
===================================


## [maven] Title for test

Expand All @@ -24,11 +24,14 @@ test data.
* [http://d.hatena.ne.jp/igapyon/20161222](http://d.hatena.ne.jp/igapyon/20161222) リンクの説明。。。


/ [ALL](https://igapyon.github.io/diary/idxall.html)


* [JDBC本](https://www.amazon.co.jp/exec/obidos/ASIN/4839913935/igapyondiary-22)
* [いがぴょん検索](https://www.google.co.jp/#pws=0&q=%E3%81%84%E3%81%8C%E3%81%B4%E3%82%87%E3%82%93)
* [いがぴょん検索サイト内](https://www.google.co.jp/#pws=0&q=site:https%3A%2F%2Figapyon.github.io%2Fdiary%2F+%E3%81%84%E3%81%8C%E3%81%B4%E3%82%87%E3%82%93)
* [いがぴょんTwitter](https://twitter.com/search?q=%23%E4%BC%8A%E8%B3%80%E6%95%8F%E6%A8%B9)
* [Twitterでシェア](https://twitter.com/intent/tweet?hashtags=%E3%81%84%E3%81%8C%E3%81%B4%E3%82%87%E3%82%93&text=%E3%83%86%E3%82%B9%E3%83%88&url=https%3A%2F%2Figapyon.github.io%2Fdiary%2F)
* [Share on Twitter](https://twitter.com/intent/tweet?hashtags=%E3%81%84%E3%81%8C%E3%81%B4%E3%82%87%E3%82%93&text=%E3%83%86%E3%82%B9%E3%83%88&url=https%3A%2F%2Figapyon.github.io%2Fdiary%2Ftest%2Fdata%2Fhatena%2Fig161226.html)
* [地図で表示](https://openstreetmap.jp/map#zoom=17&lat=35.6722478&lon=139.7214164&layers=00BFF)

#### [Publickey](http://www.publickey1.jp/)
Expand All @@ -41,7 +44,3 @@ test data.

* maven

----------------------------------------------------------------------------------------------------

## この日記について
[いがぴょんについて](https://igapyon.github.io/diary/memo/memoigapyon.html) / [日記ジェネレータ](https://github.com/igapyon/igapyonv3)
4 changes: 3 additions & 1 deletion test/data/hatena/ig161226.html.src.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ http://d.hatena.ne.jp/igapyon/20161222
* http://d.hatena.ne.jp/igapyon/20161222 リンクの説明。。。


<@localyearlist />

* <@linkamazon title="JDBC本" dp="4839913935" />
* <@linksearch title="いがぴょん検索" word="いがぴょん" />
* <@linksearch title="いがぴょん検索サイト内" word="いがぴょん" site="https://igapyon.github.io/diary/" />
* <@linksearch title="いがぴょんTwitter" word="伊賀敏樹" engine="twitter" />
* <@linkshare word="テスト" url="https://igapyon.github.io/diary/" tags="いがぴょん" />
* <@linkshare word="テスト" tags="いがぴょん" />
* <@linkmap word="mapテスト" lat="35.6722478" lon="139.7214164" />

<@rssfeed url="http://www.publickey1.jp/atom.xml" maxcount="0" />
Expand Down
Loading

0 comments on commit 4986f0b

Please sign in to comment.