つぶやきを見るページ(list_quote.pl)を追加

このコミットが含まれているのは:
守矢諏訪子 2023-11-15 00:38:04 +09:00
コミット bb8e434000
5個のファイルの変更196行の追加24行の削除

ファイルの表示

@ -2,33 +2,63 @@ package main
import (
"strings"
"net/url"
"fmt"
)
func getid(u string) (string, error) {
parse, err := url.Parse(u)
if err != nil {
return "", err
}
params, err := url.ParseQuery(parse.RawQuery)
if err != nil {
return "", err
}
id, ok := params["id"]
if !ok || len(id) == 0 {
return "", fmt.Errorf("IDを見つけられませんでした。")
}
return id[0], nil
}
/* 記事かの確認 */
func isarticle(url string) bool {
chk := strings.Split(url, "=")
func isarticle(u string) bool {
chk := strings.Split(u, "=")
return len(chk) > 2 &&
(chk[0] == "/view_news.pl?id" || chk[0] == "/view_news.pl?from" || chk[0] == "/view_news.pl?media_id" || chk[0] == "/view_news.pl?stkt")
}
/* 部分圏かの確認 */
func issubcat(url string) bool {
chk := strings.Split(url, "=")
func issubcat(u string) bool {
chk := strings.Split(u, "=")
return len(chk) > 1 &&
(chk[0] == "/list_news_category.pl?id" || chk[0] == "/list_news_category.pl?page" || chk[0] == "/list_news_category.pl?sort" || chk[0] == "/list_news_category.pl?type" || chk[0] == "/list_news_category.pl?sub_category_id") &&
strings.Contains(url, "type=bn")
strings.Contains(u, "type=bn")
}
/* 部分かの確認 */
func iscategory(url string) bool {
chk := strings.Split(url, "=")
func iscategory(u string) bool {
chk := strings.Split(u, "=")
return len(chk) > 1 &&
(chk[0] == "/list_news_category.pl?id" || chk[0] == "/list_news_category.pl?sub_category_id" || chk[0] == "/list_news_category?from") &&
!strings.Contains(url, "type=bn")
!strings.Contains(u, "type=bn")
}
/* 出版社かの確認 */
func ispublish(url string) bool {
chk := strings.Split(url, "=")
func ispublish(u string) bool {
chk := strings.Split(u, "=")
return len(chk) > 1 && (chk[0] == "/list_news_media.pl?id" || chk[0] == "/list_news_media.pl?page")
}
/* つぶやきかの確認 */
func istubayaki(u string) bool {
chk := strings.Split(u, "=")
return len(chk) > 1 &&
(chk[0] == "/list_quote.pl?id" || chk[0] == "/list_quote.pl?type" || chk[0] == "/list_quote.pl?sort" || chk[0] == "/list_quote.pl?news_id") &&
strings.Contains(u, "type=voice") &&
(strings.Contains(u, "sort=post_time") || strings.Contains(u, "sort=feedback_count"))
}

10
page.go
ファイルの表示

@ -77,13 +77,15 @@ func get(url string, cnf Config) map[string]string {
return res
}
id, _ := getid(url)
res["title"] = gettitle(body)
if isarticle(url) {
if !strings.Contains(body, "newsArticle") {
res["content"] = rmebloat(body, cnf)
} else {
res["img"] = getimg(body, cnf)
res["content"] = rmbloat(body, cnf)
res["content"] = rmbloat(id, body, cnf)
}
} else if ispublish(url) {
res["content"] = rmpbloat(body, cnf)
@ -93,6 +95,12 @@ func get(url string, cnf Config) map[string]string {
} else {
res["content"] = rmsbloat(body, cnf)
}
} else if istubayaki(url) {
if !strings.Contains(body, "quoteList") {
res["content"] = rmebloat(body, cnf)
} else {
res["content"] = rmqbloat(body, cnf)
}
} else {
if !strings.Contains(body, "注目のニュース") {
res["content"] = rmebloat(body, cnf)

ファイルの表示

@ -53,7 +53,7 @@ func rmcbloat(body string, cnf Config) string {
}
body = strings.TrimSpace("<div class=\"subCategoryNavi\" class=\"LEGACY_UI2016_subCategoryNavi\">\n" + strings.TrimSpace(body)) + "\n </div>\n"
return "<div class=\"newsArticle\">" + body + "</div>"
return "<div class=\"newsArticle\">\n<a class=\"totop\" href=\"/\">トップへ</a>\n" + body + "</div>"
}
/* エラーだけが残るまで消す */
@ -73,7 +73,36 @@ func rmebloat(body string, cnf Config) string {
body = re.ReplaceAllString(body, r.repl)
}
body = strings.TrimSpace("<div class=\"newsArticle\">\n" + strings.TrimSpace(body)) + "\n </div>\n"
body = strings.TrimSpace("<div class=\"newsArticle\">\n<a class=\"totop\" href=\"/\">トップへ</a>\n" + strings.TrimSpace(body)) + "\n </div>\n"
return body
}
/* つばやきだけが残るまで消す */
func rmqbloat(body string, cnf Config) string {
var re *regexp.Regexp
rep := []struct {
pat string
repl string
}{
{`(?s)<!DOCTYPE html>.*?<div id="bodyMainArea" class="FRAME2016_bodyMainArea" >`, ""},
{`(?s)<div class="adsenseBannerArea">.*?</html>`, ""},
{`(?s)<div class="shareButtonArea">.*?<div class="relationNewsDescription">`, `<div class="relationNewsDescription">`},
{`https://news-image.mixi.net`, cnf.imgproxy + `/news-image.mixi.net`},
{`https://img.mixi.net`, cnf.imgproxy + `/img.mixi.net`},
{`https://news.mixi.jp/`, cnf.domain + `/`},
{`(?s)<div class="sortSwitch01">.*?</div>`, ""},
// {`・ `, ""},
// {`\[`, ""},
// {`\]`, ""},
}
for _, r := range rep {
re = regexp.MustCompile(r.pat)
body = re.ReplaceAllString(body, r.repl)
}
body = strings.TrimSpace("<div class=\"newsArticle\">\n<a class=\"totop\" href=\"/\">トップへ</a>\n" + strings.TrimSpace(body)) + "\n </div>\n"
return body
}
@ -100,7 +129,7 @@ func rmsbloat(body string, cnf Config) string {
body = re.ReplaceAllString(body, r.repl)
}
body = strings.TrimSpace("<div class=\"newsArticle\">\n" + strings.TrimSpace(body)) + "\n </div>\n"
body = strings.TrimSpace("<div class=\"newsArticle\">\n<a class=\"totop\" href=\"/\">トップへ</a>\n" + strings.TrimSpace(body)) + "\n </div>\n"
return body
}
@ -128,12 +157,12 @@ func rmpbloat(body string, cnf Config) string {
body = re.ReplaceAllString(body, r.repl)
}
body = strings.TrimSpace("<div class=\"newsArticle\">\n" + strings.TrimSpace(body)) + "\n </div>\n"
body = strings.TrimSpace("<div class=\"newsArticle\">\n<a class=\"totop\" href=\"/\">トップへ</a>\n" + strings.TrimSpace(body)) + "\n </div>\n"
return body
}
/* 記事だけが残るまで消す */
func rmbloat(body string, cnf Config) string {
func rmbloat(id string, body string, cnf Config) string {
var re *regexp.Regexp
rep := []struct {
@ -157,7 +186,6 @@ func rmbloat(body string, cnf Config) string {
{`<!--`, ""},
{`(?s)<img src="https://(.*?)"`, `<img src="` + cnf.imgproxy + `/$1"`},
{`https://news-image.mixi.net`, cnf.imgproxy + `/news-image.mixi.net`},
{`(?s)<br /><p><a href="https://mixi.jp/bypass_stats.pl.*?</a></p>`, ""},
{`https://news.mixi.jp/`, cnf.domain + `/`},
}
@ -166,6 +194,10 @@ func rmbloat(body string, cnf Config) string {
body = re.ReplaceAllString(body, r.repl)
}
body = strings.TrimSpace("<div class=\"newsArticle\">\n" + strings.TrimSpace(body)) + "\n </div>\n"
body = strings.TrimSpace("<div class=\"newsArticle\">\n<a class=\"totop\" href=\"/\">トップへ</a>\n" + strings.TrimSpace(body))
if id != "" {
body += "\n<p class=\"footer\"><a class=\"tubuyaki-btn\" href=\"/list_quote.pl?news_id=" + id + "&type=voice&sort=feedback_count\">つぶやきを見る</a></p>\n"
}
body += "\n </div>\n"
return body
}

ファイルの表示

@ -10,6 +10,7 @@ body {
a {
color: #ea5fea;
text-decoration: none;
}
h1, h2 {
@ -44,13 +45,35 @@ code {
width: auto;
}
.reactionCountBalloon, .totop, p.reactions, a.tubuyaki-btn {
border: 1px solid #f976de;
border-radius: 2px;
background-color: #232629;
}
.reactionCountBalloon {
margin-left: 8px;
font-size: 60%;
padding: 0 12px;
}
.totop, p.reactions {
padding: 4px;
}
p.reactions {
font-size: 80%;
max-width: 50px;
text-align: center;
}
.newsArticle {
width: calc(100% - 20px);
max-width: 1200px;
background: #31363b;
border: 2px solid #4d4d4d;
border-radius: 10px;
margin: auto;
margin: 32px auto;
padding: 8px;
}
@ -89,7 +112,7 @@ code {
background: #3c213c;
}
.LEGACY_UI2016_subCategoryNavi > p > a, .pageList01 > div > ul > li {
.LEGACY_UI2016_subCategoryNavi > p > a, .pageList01 > div > ul > li, .pageList01 > ul > li, .pageNavigation02 > p.first, .pageNavigation02 > p.last, ul.sortTab > li {
background-color: #4d4d4d;
padding: 4px;
border: 1px solid #c625ef;
@ -97,18 +120,85 @@ code {
text-decoration: none;
}
.pageList01 > div > ul {
.pageNavigation02 > p, .pageList01 > ul > li {
padding: 8px !important;
}
.pageNavigation02 > p.none, .pageList01 > ul > li.on, ul.sortTab > li.current, ul.sortTab > li.current > a {
background-color: #232629;
color: #4d4d4d;
border-color: #4d4d4d;
}
.pageList01 > div > ul, .pageList01 > ul, .pageNavigation02 > p.first, .pageNavigation02 > p.last, ul.sortTab {
padding-left: unset;
}
.pageList01 > div > ul, .pageList01 > div > ul > li, .entryList01, .entryList01 > li, .NEWS_pickupNewsList {
.pageList01 > div > ul,
.pageList01 > div > ul > li,
.pageList01 > ul > li,
.entryList01, .entryList01 > li,
.NEWS_pickupNewsList,
.pageNavigation02 > p.first,
.pageNavigation02 > p.last,
ul.sortTab > li,
ul.voiceList01 .attributes li,
ul.listAction,
h2.newsTitle {
display: inline;
}
.newsCategoryList {
.relationNewsDescription {
margin-top: 18px;
}
ul.voiceList01 {
padding-left: 0;
}
.pageNavigation02 {
display: ruby;
}
.newsCategoryList, .timestamp, .iine, .comment, .item {
list-style: none;
}
.itemIn > .clearfix {
display: flex;
}
ul.voiceList01 > li.item {
background-color: #2f2e2f;
border: 1px dashed #4d4d4d;
margin: 8px 0;
padding: 4px;
}
ul.attributes, ul.listAction {
font-size: 80%;
color: #adadad;
}
ul.attributes {
position: absolute;
white-space: nowrap;
}
ul.listAction {
clear: both;
width: 100%;
margin-top: 5px;
margin-left: 4px;
text-align: right;
}
ul.voiceList01 ul.listAction li {
margin-left: 10px;
font-size: 100%;
display: initial;
}
.NEWS_tempPhoto {
text-align: center;
}
@ -129,3 +219,16 @@ code {
text-align: center;
margin-top: 32px;
}
li.iine > img, li.comment > img {
margin-right: 8px;
}
a.tubuyaki-btn {
display: inline-table;
padding: 24px;
}
.nextArticle > a.tubuyaki-btn {
text-align: center;
}

ファイルの表示

@ -1,4 +1,3 @@
{{template "header" .}}
<a href="/">トップへ</a>
{{ .Bdy }}
{{template "footer" .}}