Skip to content

Commit

Permalink
feat(template): Add links to diagram of each article (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhbert authored Feb 11, 2025
1 parent 7d958af commit d3e283c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
15 changes: 8 additions & 7 deletions internal/common/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@ type HabrArticle struct {
}

type StatsArticle struct {
Id int
Name string
Date time.Time
Views int
Growth int
Author domain.HabrAuthor
DayBefore int
Id int
Name string
HabrNumber int
Date time.Time
Views int
Growth int
Author domain.HabrAuthor
DayBefore int
}

type TemplateStruct struct {
Expand Down
1 change: 1 addition & 0 deletions internal/db_service/habr_sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ func GetArticlesFormLastPeriod(dt time.Time, getAll bool, global bool, db *gorm.
var stat structs.StatsArticle
stat.Id = i
stat.Name = text.CleanText(articles[i].Name)
stat.HabrNumber = articles[i].HabrNumber
stat.Date = articles[i].DateOfPublication
stat.Author = getAuthorByID(articles[i].Author.ID, db)
stat.Author.Name = text.CleanText(stat.Author.Name)
Expand Down
10 changes: 5 additions & 5 deletions templates/tex/stats.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
\hline
\textbf{Название статьи} & \textbf{Автор} & \textbf{Дата публикации} & \textbf{Дней назад*} & \textbf{Кол-во просмотров} \\ \hline
{{ range .LatestArticlesFromWeek }}
{{ .Name }} & {{ .Author.Name }} & {{ .Date.Format "2006-01-02" }} & {{ .DayBefore }} & {{ .Growth }} \\ \hline
{{ .Name }} (\hyperlink{link-{{ .HabrNumber }}}{график статистики}) & {{ .Author.Name }} & {{ .Date.Format "2006-01-02" }} & {{ .DayBefore }} & {{ .Growth }} \\ \hline
{{ end }}
\end{tabularx}
\notebox{\textbf{*} — с даты генерации страницы. \newline Дата генерации страницы может отличаться от даты последней загрузки статистики в БД.}
Expand All @@ -47,7 +47,7 @@
\hline
\textbf{Название статьи} & \textbf{Дата публикации} & \textbf{Кол-во просмотров} \\ \hline
{{ range .AllArticlesPerWeek }}
{{ .Name }} & {{ .Date.Format "2006-01-02" }} & {{ .Growth }} \\ \hline
{{ .Name }} (\hyperlink{link-{{ .HabrNumber }}}{график статистики}) & {{ .Date.Format "2006-01-02" }} & {{ .Growth }} \\ \hline
{{ end }}
\end{tabularx}
\caption{Топ-5 популярных статей за неделю (по просмотрам)}
Expand All @@ -60,7 +60,7 @@
\hline
\textbf{Название статьи} & \textbf{Дата публикации} & \textbf{Кол-во просмотров} \\ \hline
{{ range .AllArticlesGlobalWithLimit }}
{{ .Name }} & {{ .Date.Format "2006-01-02" }} & {{ .Views }} \\ \hline
{{ .Name }} (\hyperlink{link-{{ .HabrNumber }}}{график статистики}) & {{ .Date.Format "2006-01-02" }} & {{ .Views }} \\ \hline
{{ end }}
\end{tabularx}
\caption{Топ-5 популярных статей за весь период (по просмотрам)}
Expand All @@ -87,7 +87,7 @@
\textbf{Название статьи} & \textbf{Дата публикации} & \textbf{Общее кол-во просмотров} & \textbf{Кол-во просмотров за неделю} \\ \hline
\hline \endfirsthead
{{ range .AllArticlesGlobal }}
{{ .Name }} & {{ .Date.Format "2006-01-02" }} & {{ .Views }} & {{ .Growth }} \\ \hline
{{ .Name }} (\hyperlink{link-{{ .HabrNumber }}}{график статистики}) & {{ .Date.Format "2006-01-02" }} & {{ .Views }} & {{ .Growth }} \\ \hline
{{ end }}
\caption{Все статьи в блоге}
\end{longtable}
Expand Down Expand Up @@ -161,7 +161,7 @@
\begin{itemize}
\setlength{\itemsep}{-2mm}
{{ range . }}
\item {{ .HabrNumber }} --- {{ .Name }}
\item \hypertarget{link-{{ .HabrNumber }}} --- {{ .Name }}
{{ end }}
\end{itemize}
{{ end }}
Expand Down

0 comments on commit d3e283c

Please sign in to comment.