Weather and Category
This commit is contained in:
@@ -4,4 +4,6 @@ DB_HOST =localhost
|
|||||||
DB_PORT =5432
|
DB_PORT =5432
|
||||||
DB_USER =svevijesti
|
DB_USER =svevijesti
|
||||||
DB_PASSWORD =salmonela pljusti 221 hamo
|
DB_PASSWORD =salmonela pljusti 221 hamo
|
||||||
DB_NAME =svevijestiweb
|
DB_NAME =svevijestiweb
|
||||||
|
|
||||||
|
API_KEY=abb35e21bdcbad6d1b00141a2b25cf5a
|
||||||
1
go.mod
1
go.mod
@@ -15,6 +15,7 @@ require (
|
|||||||
github.com/gorilla/mux v1.8.0 // indirect
|
github.com/gorilla/mux v1.8.0 // indirect
|
||||||
github.com/gosimple/slug v1.12.0 // indirect
|
github.com/gosimple/slug v1.12.0 // indirect
|
||||||
github.com/gosimple/unidecode v1.0.1 // indirect
|
github.com/gosimple/unidecode v1.0.1 // indirect
|
||||||
|
github.com/joho/godotenv v1.5.1 // indirect
|
||||||
github.com/kennygrant/sanitize v1.2.4 // indirect
|
github.com/kennygrant/sanitize v1.2.4 // indirect
|
||||||
github.com/lib/pq v1.10.4 // indirect
|
github.com/lib/pq v1.10.4 // indirect
|
||||||
github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca // indirect
|
github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca // indirect
|
||||||
|
|||||||
2
go.sum
2
go.sum
@@ -25,6 +25,8 @@ github.com/gosimple/slug v1.12.0 h1:xzuhj7G7cGtd34NXnW/yF0l+AGNfWqwgh/IXgFy7dnc=
|
|||||||
github.com/gosimple/slug v1.12.0/go.mod h1:UiRaFH+GEilHstLUmcBgWcI42viBN7mAb818JrYOeFQ=
|
github.com/gosimple/slug v1.12.0/go.mod h1:UiRaFH+GEilHstLUmcBgWcI42viBN7mAb818JrYOeFQ=
|
||||||
github.com/gosimple/unidecode v1.0.1 h1:hZzFTMMqSswvf0LBJZCZgThIZrpDHFXux9KeGmn6T/o=
|
github.com/gosimple/unidecode v1.0.1 h1:hZzFTMMqSswvf0LBJZCZgThIZrpDHFXux9KeGmn6T/o=
|
||||||
github.com/gosimple/unidecode v1.0.1/go.mod h1:CP0Cr1Y1kogOtx0bJblKzsVWrqYaqfNOnHzpgWw4Awc=
|
github.com/gosimple/unidecode v1.0.1/go.mod h1:CP0Cr1Y1kogOtx0bJblKzsVWrqYaqfNOnHzpgWw4Awc=
|
||||||
|
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||||
|
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||||
github.com/kennygrant/sanitize v1.2.4 h1:gN25/otpP5vAsO2djbMhF/LQX6R7+O1TB4yv8NzpJ3o=
|
github.com/kennygrant/sanitize v1.2.4 h1:gN25/otpP5vAsO2djbMhF/LQX6R7+O1TB4yv8NzpJ3o=
|
||||||
github.com/kennygrant/sanitize v1.2.4/go.mod h1:LGsjYYtgxbetdg5owWB2mpgUL6e2nfw2eObZ0u0qvak=
|
github.com/kennygrant/sanitize v1.2.4/go.mod h1:LGsjYYtgxbetdg5owWB2mpgUL6e2nfw2eObZ0u0qvak=
|
||||||
github.com/lib/pq v1.10.4 h1:SO9z7FRPzA03QhHKJrH5BXA6HU1rS4V2nIVrrNC1iYk=
|
github.com/lib/pq v1.10.4 h1:SO9z7FRPzA03QhHKJrH5BXA6HU1rS4V2nIVrrNC1iYk=
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ func ArticlesForDay(store *Store, day time.Time) (articles []model.DisplayArticl
|
|||||||
|
|
||||||
result := []model.DisplayArticle{}
|
result := []model.DisplayArticle{}
|
||||||
query, err := store.Prepare(`
|
query, err := store.Prepare(`
|
||||||
select id,title, content, slug, original_url, source_id, created_at from articles where created_at > $1 and created_at < $2 and LENGTH(content) > 10 order by id desc;
|
select id,title, content, slug, original_url, source_id, created_at, category from articles where created_at > $1 and created_at < $2 and LENGTH(content) > 10 order by id desc;
|
||||||
`)
|
`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, err
|
return result, err
|
||||||
@@ -68,7 +68,7 @@ func ArticlesForDay(store *Store, day time.Time) (articles []model.DisplayArticl
|
|||||||
|
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
r := model.DisplayArticle{}
|
r := model.DisplayArticle{}
|
||||||
err = rows.Scan(&r.ID, &r.Title, &r.Content, &r.Slug, &r.OriginalUrl, &r.SourceId, &r.CreatedAt)
|
err = rows.Scan(&r.ID, &r.Title, &r.Content, &r.Slug, &r.OriginalUrl, &r.SourceId, &r.CreatedAt, &r.Category)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
@@ -96,7 +96,7 @@ func ArticleByID(store *Store, ID int, slug string) (article model.DisplayArticl
|
|||||||
|
|
||||||
result := model.DisplayArticle{}
|
result := model.DisplayArticle{}
|
||||||
query, err := store.Prepare(`
|
query, err := store.Prepare(`
|
||||||
select id,title, content, slug, original_url, source_id, created_at from articles where id = $1 and slug = $2;
|
select id,title, content, slug, original_url, source_id, created_at, category from articles where id = $1 and slug = $2;
|
||||||
`)
|
`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, err
|
return result, err
|
||||||
@@ -110,7 +110,7 @@ func ArticleByID(store *Store, ID int, slug string) (article model.DisplayArticl
|
|||||||
|
|
||||||
r := model.DisplayArticle{}
|
r := model.DisplayArticle{}
|
||||||
content := ""
|
content := ""
|
||||||
err = row.Scan(&r.ID, &r.Title, &content, &r.Slug, &r.OriginalUrl, &r.SourceId, &r.CreatedAt)
|
err = row.Scan(&r.ID, &r.Title, &content, &r.Slug, &r.OriginalUrl, &r.SourceId, &r.CreatedAt, &r.Category)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
@@ -139,7 +139,7 @@ func PreviousAndNextArticleUrlByID(store *Store, ID int) (nextUrl string, previo
|
|||||||
|
|
||||||
nextResult, previousResult := "#", "#"
|
nextResult, previousResult := "#", "#"
|
||||||
query, err := store.Prepare(`
|
query, err := store.Prepare(`
|
||||||
select id,title, content, slug, original_url, source_id, created_at from articles where id < $1 and id > $2 order by id desc limit 1;
|
select id,title, content, slug, original_url, source_id, created_at, category from articles where id < $1 and id > $2 order by id desc limit 1;
|
||||||
`)
|
`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Err 1:", err)
|
fmt.Println("Err 1:", err)
|
||||||
@@ -155,7 +155,7 @@ func PreviousAndNextArticleUrlByID(store *Store, ID int) (nextUrl string, previo
|
|||||||
|
|
||||||
r := model.DisplayArticle{}
|
r := model.DisplayArticle{}
|
||||||
content := ""
|
content := ""
|
||||||
err = row.Scan(&r.ID, &r.Title, &content, &r.Slug, &r.OriginalUrl, &r.SourceId, &r.CreatedAt)
|
err = row.Scan(&r.ID, &r.Title, &content, &r.Slug, &r.OriginalUrl, &r.SourceId, &r.CreatedAt, &r.Category)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nextResult, previousResult, err
|
return nextResult, previousResult, err
|
||||||
}
|
}
|
||||||
@@ -163,7 +163,7 @@ func PreviousAndNextArticleUrlByID(store *Store, ID int) (nextUrl string, previo
|
|||||||
previousResult = fmt.Sprintf("/%d/%s", r.ID, r.Slug)
|
previousResult = fmt.Sprintf("/%d/%s", r.ID, r.Slug)
|
||||||
|
|
||||||
query2, err := store.Prepare(`
|
query2, err := store.Prepare(`
|
||||||
select id,title, content, slug, original_url, source_id, created_at from articles where id < $1 and id > $2 order by id asc limit 1;
|
select id,title, content, slug, original_url, source_id, created_at, category from articles where id < $1 and id > $2 order by id asc limit 1;
|
||||||
`)
|
`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Err 1:", err)
|
fmt.Println("Err 1:", err)
|
||||||
@@ -178,7 +178,7 @@ func PreviousAndNextArticleUrlByID(store *Store, ID int) (nextUrl string, previo
|
|||||||
}
|
}
|
||||||
|
|
||||||
content = ""
|
content = ""
|
||||||
err = row.Scan(&r.ID, &r.Title, &content, &r.Slug, &r.OriginalUrl, &r.SourceId, &r.CreatedAt)
|
err = row.Scan(&r.ID, &r.Title, &content, &r.Slug, &r.OriginalUrl, &r.SourceId, &r.CreatedAt, &r.Category)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Err 4:", err)
|
fmt.Println("Err 4:", err)
|
||||||
return nextResult, previousResult, err
|
return nextResult, previousResult, err
|
||||||
@@ -187,48 +187,3 @@ func PreviousAndNextArticleUrlByID(store *Store, ID int) (nextUrl string, previo
|
|||||||
|
|
||||||
return nextResult, previousResult, nil
|
return nextResult, previousResult, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ArticleByCategory(store *Store, day time.Time) (cateogry []model.DisplayArticle, err error) {
|
|
||||||
|
|
||||||
result := []model.DisplayArticle{}
|
|
||||||
query, err := store.Prepare(`select id,title,content,slug,created_at,source_id,category from articles where created_at > $1 and created_at < $2 and LENGTH(content) > 10 order by id desc;`)
|
|
||||||
if err != nil {
|
|
||||||
return result, err
|
|
||||||
}
|
|
||||||
defer query.Close()
|
|
||||||
|
|
||||||
tomorow := day.AddDate(0, 0, 1)
|
|
||||||
todayDate := day.Format("2024-01-26")
|
|
||||||
tomorrowDate := tomorow.Format("2024:01:26")
|
|
||||||
|
|
||||||
rows, err := query.Query(todayDate, tomorrowDate)
|
|
||||||
if err != nil {
|
|
||||||
return result, err
|
|
||||||
}
|
|
||||||
defer rows.Close()
|
|
||||||
|
|
||||||
for rows.Next() {
|
|
||||||
r := model.DisplayArticle{}
|
|
||||||
err = rows.Scan(&r.ID, &r.Title, &r.Content, &r.Slug, &r.CreatedAt, &r.OriginalUrl, &r.SourceId, &r.CreatedAt, &r.Category)
|
|
||||||
if err != nil {
|
|
||||||
return result, err
|
|
||||||
}
|
|
||||||
|
|
||||||
ago := time.Now().Sub(r.CreatedAt)
|
|
||||||
hours := ago.Hours()
|
|
||||||
|
|
||||||
if hours < 1 {
|
|
||||||
r.FormatedCreatedAt = fmt.Sprintf("Prije %d sati.", int(math.Floor(ago.Minutes())))
|
|
||||||
} else if hours > 24 {
|
|
||||||
r.FormatedCreatedAt = r.CreatedAt.Format("28.01.2024. 01:03:05")
|
|
||||||
} else {
|
|
||||||
r.FormatedCreatedAt = fmt.Sprintf("Prije %d sati.", int(math.Floor(ago.Minutes())))
|
|
||||||
}
|
|
||||||
|
|
||||||
r.SourceName = model.SourceName(r.SourceId)
|
|
||||||
|
|
||||||
result = append(result, r)
|
|
||||||
}
|
|
||||||
return result, nil
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -25,11 +25,25 @@ func rootHandler(wr http.ResponseWriter, req *http.Request) {
|
|||||||
|
|
||||||
dayBefore := "/dan/" + time.Now().Add(-24*time.Hour).Format("2006-01-02")
|
dayBefore := "/dan/" + time.Now().Add(-24*time.Hour).Format("2006-01-02")
|
||||||
|
|
||||||
|
cities := []string{"Sarajevo", "Banja Luka", "Zenica", "Tuzla", "Mostar"}
|
||||||
|
|
||||||
|
var weatherInfo []WeatherData
|
||||||
|
for _, city := range cities {
|
||||||
|
data, err := getWeather(city)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error fetching weather for %s: %v\n", city, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
weatherInfo = append(weatherInfo, data)
|
||||||
|
}
|
||||||
|
|
||||||
data := map[string]interface{}{
|
data := map[string]interface{}{
|
||||||
"title": title,
|
"title": title,
|
||||||
"articles": articles,
|
"articles": articles,
|
||||||
"previous": dayBefore,
|
"previous": dayBefore,
|
||||||
"next": "/",
|
"next": "/",
|
||||||
|
"weatherInfo": weatherInfo,
|
||||||
|
"categories": CategoryMenu,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = templates.ExecuteTemplate(wr, "homeHTML", data)
|
err = templates.ExecuteTemplate(wr, "homeHTML", data)
|
||||||
@@ -63,11 +77,24 @@ func dailyArticlesHandler(wr http.ResponseWriter, req *http.Request) {
|
|||||||
http.Error(wr, err.Error(), http.StatusInternalServerError)
|
http.Error(wr, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cities := []string{"Sarajevo", "Banja Luka", "Zenica", "Tuzla", "Mostar"}
|
||||||
|
|
||||||
|
var weatherInfo []WeatherData
|
||||||
|
for _, city := range cities {
|
||||||
|
data, err := getWeather(city)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error fetching weather for %s: %v\n", city, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
weatherInfo = append(weatherInfo, data)
|
||||||
|
}
|
||||||
|
|
||||||
data := map[string]interface{}{
|
data := map[string]interface{}{
|
||||||
"title": title,
|
"title": title,
|
||||||
"articles": articles,
|
"articles": articles,
|
||||||
"previous": dayBefore,
|
"previous": dayBefore,
|
||||||
"next": dayAfter,
|
"next": dayAfter,
|
||||||
|
"weatherInfo": weatherInfo,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = templates.ExecuteTemplate(wr, "homeHTML", data)
|
err = templates.ExecuteTemplate(wr, "homeHTML", data)
|
||||||
@@ -98,10 +125,11 @@ func articleHandler(wr http.ResponseWriter, req *http.Request) {
|
|||||||
|
|
||||||
title := article.Title
|
title := article.Title
|
||||||
data := map[string]interface{}{
|
data := map[string]interface{}{
|
||||||
"title": title,
|
"title": title,
|
||||||
"article": article,
|
"article": article,
|
||||||
"previous": previous,
|
"previous": previous,
|
||||||
"next": next,
|
"next": next,
|
||||||
|
"categories": CategoryMenu,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = templates.ExecuteTemplate(wr, "articleHTML", data)
|
err = templates.ExecuteTemplate(wr, "articleHTML", data)
|
||||||
|
|||||||
@@ -4,31 +4,65 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/gorilla/mux"
|
||||||
"gitlab.com/kbr4/svevijesti/internal/database"
|
"gitlab.com/kbr4/svevijesti/internal/database"
|
||||||
"gitlab.com/kbr4/svevijesti/internal/model"
|
"gitlab.com/kbr4/svevijesti/internal/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func categoryHandler(wr http.ResponseWriter, r *http.Request) {
|
var CategoryMenu = []string{
|
||||||
|
"Politika",
|
||||||
|
"Biznis",
|
||||||
|
"Sport",
|
||||||
|
"Magazin",
|
||||||
|
"Nauka i tehnologija",
|
||||||
|
"Ostalo",
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleCategory(wr http.ResponseWriter, r *http.Request) {
|
||||||
|
vars := mux.Vars(r)
|
||||||
|
category := vars["category"]
|
||||||
|
|
||||||
store, err := database.Connect()
|
store, err := database.Connect()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(wr, err.Error(), http.StatusInternalServerError)
|
http.Error(wr, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer store.Close()
|
||||||
|
|
||||||
|
currentDate, err := time.Parse("2006-01-02", category)
|
||||||
|
if err != nil {
|
||||||
|
currentDate = time.Now()
|
||||||
}
|
}
|
||||||
|
|
||||||
articles, err := database.ArticleByCategory(store, time.Now())
|
articles, err := database.ArticlesForDay(store, currentDate)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(wr, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
articlesByCategory := make(map[string][]model.DisplayArticle)
|
articlesByCategory := make(map[string][]model.DisplayArticle)
|
||||||
|
|
||||||
for _, article := range articles {
|
for _, article := range articles {
|
||||||
articlesByCategory[article.Category] = append(articlesByCategory[article.Category], article)
|
articlesByCategory[article.Category] = append(articlesByCategory[article.Category], article)
|
||||||
}
|
}
|
||||||
|
|
||||||
for category, articles := range articlesByCategory {
|
var categories []string
|
||||||
data := map[string]interface{}{"Category": category, "Articles": articles}
|
for cat := range articlesByCategory {
|
||||||
err := templates.ExecuteTemplate(wr, "categoryHTML", data)
|
categories = append(categories, cat)
|
||||||
if err != nil {
|
}
|
||||||
panic(err)
|
|
||||||
}
|
prevDay := currentDate.AddDate(0, 0, -1)
|
||||||
|
|
||||||
|
data := map[string]interface{}{
|
||||||
|
"title": category,
|
||||||
|
"currentCategory": category,
|
||||||
|
"articles": articlesByCategory[category],
|
||||||
|
"categories": CategoryMenu,
|
||||||
|
"previous": prevDay.Format("2006-01-02"),
|
||||||
|
"next": "/",
|
||||||
|
}
|
||||||
|
err = templates.ExecuteTemplate(wr, "categoryHTML", data)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(wr, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,6 @@ func CreateRoutes() *mux.Router {
|
|||||||
r.HandleFunc("/{id:[0-9]+}/{slug}", articleHandler)
|
r.HandleFunc("/{id:[0-9]+}/{slug}", articleHandler)
|
||||||
r.HandleFunc("/", rootHandler)
|
r.HandleFunc("/", rootHandler)
|
||||||
r.HandleFunc("/weather", WeatherHandler)
|
r.HandleFunc("/weather", WeatherHandler)
|
||||||
r.HandleFunc("/{category}", categoryHandler)
|
r.HandleFunc("/{category}", handleCategory)
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,27 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/joho/godotenv"
|
||||||
)
|
)
|
||||||
|
|
||||||
const apiKey = "abb35e21bdcbad6d1b00141a2b25cf5a"
|
var apiKey string
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
err := godotenv.Load()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error loading .env file:", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
apiKey = os.Getenv("API_KEY")
|
||||||
|
|
||||||
|
if apiKey == "" {
|
||||||
|
fmt.Println("API_KEY environment variable not set.")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type WeatherData struct {
|
type WeatherData struct {
|
||||||
Coord struct {
|
Coord struct {
|
||||||
@@ -74,24 +92,13 @@ func WeatherHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
data := map[string]interface{}{
|
data := map[string]interface{}{
|
||||||
"title": title,
|
"title": title,
|
||||||
"weatherInfo": weatherInfo,
|
"weatherInfo": weatherInfo,
|
||||||
|
"categories": CategoryMenu,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := templates.ExecuteTemplate(w, "fullweatherHTML", data)
|
err := templates.ExecuteTemplate(w, "weatherHTML", data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error executing template:", err)
|
fmt.Println("Error executing template:", err)
|
||||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
for _, info := range weatherInfo {
|
|
||||||
widgetData := map[string]interface{}{
|
|
||||||
"Temperature": info.Main.Temp,
|
|
||||||
"City": info.Name,
|
|
||||||
}
|
|
||||||
err := templates.ExecuteTemplate(w, "weatherwidgetHTML", widgetData)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Error executing template:", err)
|
|
||||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@@ -123,6 +123,15 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
category_options = ['politics','business','sport','magazine','scitech']
|
category_options = ['politics','business','sport','magazine','scitech']
|
||||||
|
|
||||||
|
category_translation = {
|
||||||
|
'politics': 'Politika',
|
||||||
|
'business': 'Biznis',
|
||||||
|
'sport': 'Sport',
|
||||||
|
'magazine': 'Magazin',
|
||||||
|
'scitech': 'Nauka i tehnologija',
|
||||||
|
'other': 'Ostalo',
|
||||||
|
}
|
||||||
|
|
||||||
if ttk > 1900:
|
if ttk > 1900:
|
||||||
title_text = slice_title_if_needed(title_text)
|
title_text = slice_title_if_needed(title_text)
|
||||||
try:
|
try:
|
||||||
@@ -146,9 +155,10 @@ if __name__ == '__main__':
|
|||||||
else:
|
else:
|
||||||
category = 'other'
|
category = 'other'
|
||||||
|
|
||||||
|
category = category_translation.get(category, category.capitalize())
|
||||||
|
|
||||||
vector = embeddings.embed_query(generated_text)
|
vector = embeddings.embed_query(generated_text)
|
||||||
|
|
||||||
print(f"Title: {title}")
|
|
||||||
print(f"Category: {category}")
|
print(f"Category: {category}")
|
||||||
|
|
||||||
if not is_similar_data(title, text, link, vector, threshold=0.98):
|
if not is_similar_data(title, text, link, vector, threshold=0.98):
|
||||||
|
|||||||
@@ -1,17 +1,5 @@
|
|||||||
{{define "articlesHTML"}}
|
{{define "articlesHTML"}}
|
||||||
<script>
|
|
||||||
function createPreview(content) {
|
|
||||||
var slicedContent = content.slice(0, 200);
|
|
||||||
if (content.length > 200) {
|
|
||||||
slicedContent += '...';
|
|
||||||
}
|
|
||||||
return slicedContent;
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<div class="list">
|
|
||||||
<div class="slide-container">
|
|
||||||
</div>
|
|
||||||
{{range .articles}}
|
{{range .articles}}
|
||||||
<article class="news-article">
|
<article class="news-article">
|
||||||
<div class="article_content">
|
<div class="article_content">
|
||||||
@@ -22,9 +10,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<a href="/{{.ID}}/{{.Slug}}">
|
<a href="/{{.ID}}/{{.Slug}}">
|
||||||
<div class="prewi" data-content="{{.Content}}" data-title="{{.Title}}" data-link="/{{.ID}}/{{.Slug}}"></div>
|
<div class="prewi" data-content="{{.Content}}"></div>
|
||||||
</a>
|
</a>
|
||||||
<div class="timestamp"> starenovine - {{ .FormatedCreatedAt }}</div>
|
<div class="timestamp"> starenovine - {{ .FormatedCreatedAt }} - {{.Category}}</div>
|
||||||
</article>
|
</article>
|
||||||
{{else}}
|
{{else}}
|
||||||
<div class="empty">
|
<div class="empty">
|
||||||
@@ -34,49 +22,18 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
let i = 1;
|
function createPewiev(content) {
|
||||||
let allArticles = []
|
let slicedContent = content.slice(0,200);
|
||||||
let lastArticles = []
|
if (content.length > 200){
|
||||||
let previewDivs = document.querySelectorAll('.prewi');
|
slicedContent += '...'
|
||||||
previewDivs.forEach(function (previewDiv) {
|
|
||||||
let content = previewDiv.getAttribute('data-content');
|
|
||||||
let title = previewDiv.getAttribute('data-title')
|
|
||||||
let link = previewDiv.getAttribute('data-link')
|
|
||||||
allArticles.push({content,title,link})
|
|
||||||
if (allArticles.length > 4){
|
|
||||||
previewDiv.textContent = createPreview(content);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
lastArticles.push({title,content,link})
|
|
||||||
}
|
|
||||||
i = i+1;
|
|
||||||
});
|
|
||||||
slideArticles = lastArticles.slice(0, 4);
|
|
||||||
function createSlide(){
|
|
||||||
if (slideArticles.length > 0) {
|
|
||||||
let temp = slideArticles.shift()
|
|
||||||
document.querySelector('.slide-container').innerHTML = `
|
|
||||||
<div class="ar-title">
|
|
||||||
<a href="${temp.link}">
|
|
||||||
${temp.title}
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<a href="${temp.link}">
|
|
||||||
<div class="prewi">${createPreview(temp.content)}</div>
|
|
||||||
</a>
|
|
||||||
`
|
|
||||||
slideArticles.push(temp)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
createSlide();
|
|
||||||
setInterval(createSlide, 5000)
|
|
||||||
|
|
||||||
let articleDivs = document.querySelectorAll('.news-article');
|
|
||||||
for (let i = 0; i < 4; i++) {
|
|
||||||
if (articleDivs[i]) {
|
|
||||||
articleDivs[i].remove();
|
|
||||||
}
|
}
|
||||||
|
return slicedContent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let previewDivs = document.querySelectorAll('.prewi')
|
||||||
|
previewDivs.forEach(function(previewDiv){
|
||||||
|
let content = previewDiv.getAttribute('data-content')
|
||||||
|
previewDiv.textContent = createPewiev(content)
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|||||||
40
web/data/categoryarticles.html
Normal file
40
web/data/categoryarticles.html
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
{{define "articlecategoryHTML"}}
|
||||||
|
|
||||||
|
<h1>{{.category}}</h1>
|
||||||
|
{{range .articles}}
|
||||||
|
<article class="news-article">
|
||||||
|
<div class="article_content">
|
||||||
|
<div class="ar-title">
|
||||||
|
<a href="/{{.ID}}/{{.Slug}}">
|
||||||
|
{{.Title}}
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<a href="/{{.ID}}/{{.Slug}}">
|
||||||
|
<div class="prewi" data-content="{{.Content}}" data-title="{{.Title}}" data-link="/{{.ID}}/{{.Slug}}"></div>
|
||||||
|
</a>
|
||||||
|
<div class="timestamp"> starenovine - {{ .FormatedCreatedAt }} - {{.Category}}</div>
|
||||||
|
</article>
|
||||||
|
{{else}}
|
||||||
|
<div class="empty">
|
||||||
|
Nema članaka za izabrani datum.
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function createPewiev(content) {
|
||||||
|
let slicedContent = content.slice(0,200);
|
||||||
|
if (content.length > 200){
|
||||||
|
slicedContent += '...'
|
||||||
|
}
|
||||||
|
return slicedContent
|
||||||
|
}
|
||||||
|
|
||||||
|
let previewDivs = document.querySelectorAll('.prewi')
|
||||||
|
previewDivs.forEach(function(previewDiv){
|
||||||
|
let content = previewDiv.getAttribute('data-content')
|
||||||
|
previewDiv.textContent = createPewiev(content)
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{{end}}
|
||||||
44
web/data/categorymenu.html
Normal file
44
web/data/categorymenu.html
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
{{define "categorymenuHTML"}}
|
||||||
|
<nav class="hed">
|
||||||
|
<div id="small-menu" onclick="handleSmallMenu()">
|
||||||
|
Menu
|
||||||
|
</div>
|
||||||
|
<div class="menu">
|
||||||
|
<a href="/">
|
||||||
|
<div class="home-icon" title="Pocetna">
|
||||||
|
<div class="home-text">Pocetna</div>
|
||||||
|
<i class="fa fa-home" style="font-size:48px;color:white"></i>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
{{range .categories}}
|
||||||
|
<a href="/{{ . }}">
|
||||||
|
<div class="home-icon" title="{{ . }}">
|
||||||
|
{{ . }}
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
{{end}}
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
|
||||||
|
function handleSmallMenu (){
|
||||||
|
let menu = document.querySelector('.menu')
|
||||||
|
menu.classList.toggle('show-menu')
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleScroll = function(event) {
|
||||||
|
const top = window.scrollY;
|
||||||
|
const header = document.querySelector('.hed');
|
||||||
|
const headerBottom = header.offsetTop + header.offsetHeight;
|
||||||
|
|
||||||
|
if (top >= headerBottom) {
|
||||||
|
header.classList.add('fixed');
|
||||||
|
} else {
|
||||||
|
header.classList.remove('fixed');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window.addEventListener('scroll', handleScroll);
|
||||||
|
</script>
|
||||||
|
{{end}}
|
||||||
@@ -1,13 +1,33 @@
|
|||||||
{{define "footerHTML"}}
|
{{define "footerHTML"}}
|
||||||
|
|
||||||
<center><div class="sign">SN</div></center>
|
|
||||||
<footer>
|
<footer>
|
||||||
<center>
|
<center>
|
||||||
<nav class="fot">
|
<br>
|
||||||
<a href="{{.previous}}"><----</a> |
|
<nav class="hed">
|
||||||
<a href="/">Početna</a> |
|
<a href="{{.previous}}">
|
||||||
<a href="{{.next}}">----></a>
|
<div class="arr-pr-nx" title="Prethodna">
|
||||||
</nav>
|
<svg width="18px" height="17px" viewBox="0 0 18 17" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||||
|
<g id="prev" transform="translate(8.500000, 8.500000) scale(-1, 1) translate(-8.500000, -8.500000)">
|
||||||
|
<polygon class="arrow" points="16.3746667 8.33860465 7.76133333 15.3067621 6.904 14.3175671 14.2906667 8.34246869 6.908 2.42790698 7.76 1.43613596"></polygon>
|
||||||
|
<polygon class="arrow-fixed" points="16.3746667 8.33860465 7.76133333 15.3067621 6.904 14.3175671 14.2906667 8.34246869 6.908 2.42790698 7.76 1.43613596"></polygon>
|
||||||
|
<path d="M-1.48029737e-15,0.56157424 L-1.48029737e-15,16.1929159 L9.708,8.33860465 L-2.66453526e-15,0.56157424 L-1.48029737e-15,0.56157424 Z M1.33333333,3.30246869 L7.62533333,8.34246869 L1.33333333,13.4327013 L1.33333333,3.30246869 L1.33333333,3.30246869 Z"></path>
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
<a href="{{.next}}">
|
||||||
|
<div class="arr-pr-nx" title="Sledeca">
|
||||||
|
<svg width="18px" height="17px" viewBox="-1 0 18 17" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||||
|
<g>
|
||||||
|
<polygon class="arrow" points="16.3746667 8.33860465 7.76133333 15.3067621 6.904 14.3175671 14.2906667 8.34246869 6.908 2.42790698 7.76 1.43613596"></polygon>
|
||||||
|
<polygon class="arrow-fixed" points="16.3746667 8.33860465 7.76133333 15.3067621 6.904 14.3175671 14.2906667 8.34246869 6.908 2.42790698 7.76 1.43613596"></polygon>
|
||||||
|
<path d="M-4.58892184e-16,0.56157424 L-4.58892184e-16,16.1929159 L9.708,8.33860465 L-1.64313008e-15,0.56157424 L-4.58892184e-16,0.56157424 Z M1.33333333,3.30246869 L7.62533333,8.34246869 L1.33333333,13.4327013 L1.33333333,3.30246869 L1.33333333,3.30246869 Z"></path>
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
</nav>
|
||||||
</center>
|
</center>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|||||||
23
web/data/fullweather.html
Normal file
23
web/data/fullweather.html
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{{define "fullweatherHTML"}}
|
||||||
|
|
||||||
|
<h2 class="w-title">{{.title}}</h2>
|
||||||
|
<div class="weather-container">
|
||||||
|
{{range .weatherInfo}}
|
||||||
|
<div class="weather-w">
|
||||||
|
<h3>{{.Name}}</h3>
|
||||||
|
{{with index .Weather 0}}
|
||||||
|
<div class="weather-info">Opis: {{.Description}}</div>
|
||||||
|
{{end}}
|
||||||
|
<div class="weather-info">Temperatura: {{.Main.Temp}}°C</div>
|
||||||
|
<div class="weather-info">Osecaj: {{.Main.FellsLike}}°C</div>
|
||||||
|
<div class="weather-info">Pritisak:{{.Main.Preassure}} hPa</div>
|
||||||
|
<div class="weather-info">Vlaznost: {{.Main.Humidity}}%</div>
|
||||||
|
<div class="weather-info">Min Temp: {{.Main.TempMin}}°C</div>
|
||||||
|
<div class="weather-info">Max Temp: {{.Main.TempMax}}°C</div>
|
||||||
|
<div class="weather-info">Vetar: {{.Wind.Speed}} m/s</div>
|
||||||
|
<div class="weather-info">Oblaci: {{.Clouds.All}}%</div>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{end}}
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
font-size: 1.5em;
|
font-size: 1.2em;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
overflow-x: hidden;
|
overflow-x: hidden;
|
||||||
background-color: black;
|
background-color: black;
|
||||||
@@ -159,14 +159,11 @@ h1#title {
|
|||||||
|
|
||||||
.hed {
|
.hed {
|
||||||
background-color: #0B173B;
|
background-color: #0B173B;
|
||||||
text-decoration: none;
|
|
||||||
color: white;
|
color: white;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
padding-top: 5px;
|
|
||||||
padding-bottom: 5px;
|
|
||||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
|
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
|
||||||
gap: 5%;
|
gap: 5%;
|
||||||
transition: background-color 0.5s var(--ease);
|
transition: background-color 0.5s var(--ease);
|
||||||
@@ -187,7 +184,6 @@ h1#title {
|
|||||||
gap: 10px;
|
gap: 10px;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.article_content > a {
|
.article_content > a {
|
||||||
color: white;
|
color: white;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
@@ -266,14 +262,78 @@ pre.article_content {
|
|||||||
font-size: 8;
|
font-size: 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#small-menu{
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.menu{
|
||||||
|
width: 100%;
|
||||||
|
text-decoration: none;
|
||||||
|
color: white;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-evenly;
|
||||||
|
align-items: center;
|
||||||
|
padding-top: 5px;
|
||||||
|
padding-bottom: 5px;
|
||||||
|
}
|
||||||
|
.menu > a {
|
||||||
|
color: white;
|
||||||
|
gap: 10px;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
.home-text{
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@media only screen and (max-width: 600px) {
|
@media only screen and (max-width: 600px) {
|
||||||
|
#small-menu{
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
.fa-home{
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.home-text{
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.menu{
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.menu.show-menu{
|
||||||
|
width: 100%;
|
||||||
|
text-decoration: none;
|
||||||
|
color: white;
|
||||||
|
display: grid;
|
||||||
|
transition: background-color 0.5s var(--ease);
|
||||||
|
}
|
||||||
|
.hed{
|
||||||
|
padding-top: 5px;
|
||||||
|
padding-bottom: 5px;
|
||||||
|
height: fit-content;
|
||||||
|
display: grid;
|
||||||
|
gap: 0 ;
|
||||||
|
}
|
||||||
|
.menu.show-menu > a{
|
||||||
|
text-decoration: none;
|
||||||
|
border-image: linear-gradient(90deg, rgba(8, 8, 8, 1) 0%, rgba(179, 150, 121, 1) 21%, rgba(0, 0, 0, 1) 37%, rgba(98, 87, 75, 1) 63%, rgba(0, 0, 0, 1) 100%);
|
||||||
|
}
|
||||||
|
.home-icon {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
width: 10px;
|
||||||
|
height: 10px;
|
||||||
|
background-color: #0B173B;
|
||||||
|
border-radius: 50%;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: background-color 0.5s var(--ease);
|
||||||
|
}
|
||||||
|
|
||||||
#weather {
|
#weather {
|
||||||
display: grid;
|
display: grid;
|
||||||
margin-bottom: 4%;
|
margin-bottom: 4%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.weather-widget {
|
.weather-widget {
|
||||||
width: 90vw;
|
width: 90vw;
|
||||||
height: 20px;
|
height: 20px;
|
||||||
@@ -303,8 +363,8 @@ html {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.arr-pr-nx svg {
|
.arr-pr-nx svg {
|
||||||
width: 60px;
|
width: 40px;
|
||||||
height: 60px;
|
height: 40px;
|
||||||
margin: 0 1rem;
|
margin: 0 1rem;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
overflow: visible;
|
overflow: visible;
|
||||||
@@ -359,8 +419,8 @@ html {
|
|||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
width: 60px;
|
width: 40px;
|
||||||
height: 60px;
|
height: 40px;
|
||||||
background-color: #0B173B;
|
background-color: #0B173B;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
@@ -381,8 +441,6 @@ html {
|
|||||||
color: #FF0000;
|
color: #FF0000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|||||||
@@ -14,49 +14,9 @@
|
|||||||
</pre>
|
</pre>
|
||||||
</a>
|
</a>
|
||||||
</center>
|
</center>
|
||||||
<nav class="hed">
|
|
||||||
<a href="{{.previous}}">
|
{{template "categorymenuHTML" .}}
|
||||||
<div class="arr-pr-nx" title="Prethodna">
|
|
||||||
<svg width="18px" height="17px" viewBox="0 0 18 17" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
||||||
<g id="prev" transform="translate(8.500000, 8.500000) scale(-1, 1) translate(-8.500000, -8.500000)">
|
|
||||||
<polygon class="arrow" points="16.3746667 8.33860465 7.76133333 15.3067621 6.904 14.3175671 14.2906667 8.34246869 6.908 2.42790698 7.76 1.43613596"></polygon>
|
|
||||||
<polygon class="arrow-fixed" points="16.3746667 8.33860465 7.76133333 15.3067621 6.904 14.3175671 14.2906667 8.34246869 6.908 2.42790698 7.76 1.43613596"></polygon>
|
|
||||||
<path d="M-1.48029737e-15,0.56157424 L-1.48029737e-15,16.1929159 L9.708,8.33860465 L-2.66453526e-15,0.56157424 L-1.48029737e-15,0.56157424 Z M1.33333333,3.30246869 L7.62533333,8.34246869 L1.33333333,13.4327013 L1.33333333,3.30246869 L1.33333333,3.30246869 Z"></path>
|
|
||||||
</g>
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
</a>
|
|
||||||
<a href="/">
|
|
||||||
<div class="home-icon" title="Pocetna">
|
|
||||||
<i class="fa fa-home" style="font-size:48px;color:white"></i>
|
|
||||||
</div>
|
|
||||||
</a>
|
|
||||||
<a href="{{.next}}">
|
|
||||||
<div class="arr-pr-nx" title="Sledeca">
|
|
||||||
<svg width="18px" height="17px" viewBox="-1 0 18 17" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
||||||
<g>
|
|
||||||
<polygon class="arrow" points="16.3746667 8.33860465 7.76133333 15.3067621 6.904 14.3175671 14.2906667 8.34246869 6.908 2.42790698 7.76 1.43613596"></polygon>
|
|
||||||
<polygon class="arrow-fixed" points="16.3746667 8.33860465 7.76133333 15.3067621 6.904 14.3175671 14.2906667 8.34246869 6.908 2.42790698 7.76 1.43613596"></polygon>
|
|
||||||
<path d="M-4.58892184e-16,0.56157424 L-4.58892184e-16,16.1929159 L9.708,8.33860465 L-1.64313008e-15,0.56157424 L-4.58892184e-16,0.56157424 Z M1.33333333,3.30246869 L7.62533333,8.34246869 L1.33333333,13.4327013 L1.33333333,3.30246869 L1.33333333,3.30246869 Z"></path>
|
|
||||||
</g>
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
</a>
|
|
||||||
</nav>
|
|
||||||
<br>
|
|
||||||
</header>
|
|
||||||
<script>
|
|
||||||
const handleScroll = function(event) {
|
|
||||||
const top = window.scrollY;
|
|
||||||
const header = document.querySelector('.hed');
|
|
||||||
const headerBottom = header.offsetTop + header.offsetHeight;
|
|
||||||
|
|
||||||
if (top >= headerBottom) {
|
</br>
|
||||||
header.classList.add('fixed');
|
</header>
|
||||||
} else {
|
|
||||||
header.classList.remove('fixed');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
window.addEventListener('scroll', handleScroll);
|
|
||||||
</script>
|
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|||||||
@@ -1,80 +0,0 @@
|
|||||||
{{define "weatherHTML"}}
|
|
||||||
<a class="w-link" href="/weather">
|
|
||||||
<div id="weather">
|
|
||||||
<div class="weather-widget" id="weather-widget-sarajevo">
|
|
||||||
<div><span id="city-sarajevo">Učitavanje...</span></div>
|
|
||||||
<div id="temperature-sarajevo">Učitavanje...</div>
|
|
||||||
</div>
|
|
||||||
<div class="weather-widget" id="weather-widget-banja-luka">
|
|
||||||
<div><span id="city-banja-luka">Učitavanje...</span></div>
|
|
||||||
<div id="temperature-banja-luka">Učitavanje...</div>
|
|
||||||
</div>
|
|
||||||
<div class="weather-widget" id="weather-widget-tuzla">
|
|
||||||
<div><span id="city-tuzla">Učitavanje...</span></div>
|
|
||||||
<div id="temperature-tuzla">Učitavanje...</div>
|
|
||||||
</div>
|
|
||||||
<div class="weather-widget" id="weather-widget-zenica">
|
|
||||||
<div><span id="city-zenica">Učitavanje...</span></div>
|
|
||||||
<div id="temperature-zenica">Učitavanje...</div>
|
|
||||||
</div>
|
|
||||||
<div class="weather-widget" id="weather-widget-mostar">
|
|
||||||
<div><span id="city-mostar">Učitavanje...</span></div>
|
|
||||||
<div id="temperature-mostar">Učitavanje...</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</a>
|
|
||||||
|
|
||||||
|
|
||||||
<script>
|
|
||||||
const apiKey = 'abb35e21bdcbad6d1b00141a2b25cf5a';
|
|
||||||
|
|
||||||
const cities = [
|
|
||||||
{ name: 'Sarajevo', id: 'sarajevo' },
|
|
||||||
{ name: 'Banja Luka', id: 'banja-luka' },
|
|
||||||
{ name: 'Tuzla', id: 'tuzla' },
|
|
||||||
{ name: 'Zenica', id:'zenica'},
|
|
||||||
{ name: 'Mostar', id: 'mostar' }
|
|
||||||
];
|
|
||||||
|
|
||||||
async function getWeatherData(city) {
|
|
||||||
const apiUrl = `https://api.openweathermap.org/data/2.5/weather?q=${city.name}&appid=${apiKey}&units=metric&lang=hr`;
|
|
||||||
try {
|
|
||||||
const response = await fetch(apiUrl);
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
||||||
}
|
|
||||||
const data = await response.json();
|
|
||||||
updateUI(data, city.id);
|
|
||||||
} catch (error) {
|
|
||||||
console.error(`Error fetching data for ${city.name}:`, error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateUI(data, cityId) {
|
|
||||||
const cityElement = document.getElementById(`city-${cityId}`);
|
|
||||||
const temperatureElement = document.getElementById(`temperature-${cityId}`);
|
|
||||||
|
|
||||||
cityElement.textContent = data.name;
|
|
||||||
temperatureElement.textContent = `${data.main.temp}°C`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function cToL(text) {
|
|
||||||
const cyrillicChars = 'АБВГДЂЕЖЗИЈКЛЉМНЊОПРСТЋУФХЦЧЏШабвгдђежзијклљмнњопрстћуфхцчџш';
|
|
||||||
const latinChars = 'ABVGĐEŽZIJKLJMNJOPRSTĆUFHCČDŽŠabvgdđežzijkljmnjoprstćufhčdžš';
|
|
||||||
|
|
||||||
return text
|
|
||||||
.split('')
|
|
||||||
.map(char => {
|
|
||||||
const index = cyrillicChars.indexOf(char);
|
|
||||||
return index !== -1 ? latinChars[index] : char;
|
|
||||||
})
|
|
||||||
.join('');
|
|
||||||
}
|
|
||||||
|
|
||||||
cities.forEach(city => {
|
|
||||||
getWeatherData(city);
|
|
||||||
});
|
|
||||||
|
|
||||||
</script>
|
|
||||||
|
|
||||||
{{end}}
|
|
||||||
13
web/data/weatherwidget.html
Normal file
13
web/data/weatherwidget.html
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{{define "weatherwidgetHTML"}}
|
||||||
|
<a class="w-link" href="/weather">
|
||||||
|
<div id="weather">
|
||||||
|
{{range .weatherInfo}}
|
||||||
|
<div class="weather-widget">
|
||||||
|
<div><span id="city">{{.Name}}</span></div>
|
||||||
|
<div id="temperature">{{.Main.Temp}} °C</div>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
<br>
|
||||||
|
{{end}}
|
||||||
@@ -4,8 +4,7 @@
|
|||||||
<body>
|
<body>
|
||||||
{{template "headerHTML" .}}
|
{{template "headerHTML" .}}
|
||||||
|
|
||||||
{{template "weatherHTML"}}
|
{{template "weatherwidgetHTML"}}
|
||||||
|
|
||||||
|
|
||||||
{{template "singleArticleHTML" .}}
|
{{template "singleArticleHTML" .}}
|
||||||
|
|
||||||
|
|||||||
@@ -4,43 +4,8 @@
|
|||||||
<body>
|
<body>
|
||||||
{{template "headerHTML" .}}
|
{{template "headerHTML" .}}
|
||||||
|
|
||||||
{{template "weatherHTML"}}
|
{{template "articlecategoryHTML" .}}
|
||||||
|
|
||||||
|
|
||||||
<h1>{{.Category}}</h1>
|
|
||||||
{{range .Articles}}
|
|
||||||
<article class="news-article">
|
|
||||||
<div class="article_content">
|
|
||||||
<div class="ar-title">
|
|
||||||
<a href="/{{.ID}}/{{.Slug}}">
|
|
||||||
{{.Title}}
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<a href="/{{.ID}}/{{.Slug}}">
|
|
||||||
<div class="prewi" data-content="{{.Content}}" data-title="{{.Title}}" data-link="/{{.ID}}/{{.Slug}}"></div>
|
|
||||||
</a>
|
|
||||||
<div class="timestamp"> starenovine - {{ .FormatedCreatedAt }}</div>
|
|
||||||
</article>
|
|
||||||
{{else}}
|
|
||||||
<div class="empty">
|
|
||||||
Nema članaka za izabrani datum.
|
|
||||||
</div>
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
<script>
|
|
||||||
function createPreview(content) {
|
|
||||||
let slicedContent = content.slice(0,200);
|
|
||||||
if (content.length > 200){
|
|
||||||
slicedContent += '...'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let previewDiv = document.querySelectorAll(".prewi");
|
|
||||||
previewDivs.forEach(function (previewDiv) {
|
|
||||||
let content = document.getAttribute('data-content')
|
|
||||||
previewDiv.textContent = createPreview(content)
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
{{template "footerHTML" .}}
|
{{template "footerHTML" .}}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<body>
|
<body>
|
||||||
{{template "headerHTML" .}}
|
{{template "headerHTML" .}}
|
||||||
|
|
||||||
{{template "weatherHTML"}}
|
{{template "weatherwidgetHTML"}}
|
||||||
|
|
||||||
{{template "articlesHTML" .}}
|
{{template "articlesHTML" .}}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
{{define "homeHTML"}}
|
{{define "homeHTML"}}
|
||||||
|
|
||||||
{{template "headHTML" .}}
|
{{template "headHTML" .}}
|
||||||
<body>
|
<body>
|
||||||
{{template "headerHTML" .}}
|
{{template "headerHTML" .}}
|
||||||
|
|
||||||
{{template "weatherHTML"}}
|
{{template "weatherwidgetHTML" .}}
|
||||||
|
|
||||||
{{template "articlesHTML" .}}
|
{{template "articlesHTML" .}}
|
||||||
|
|
||||||
|
|||||||
@@ -1,28 +1,10 @@
|
|||||||
{{define "fullweatherHTML"}}
|
{{define "weatherHTML"}}
|
||||||
|
|
||||||
{{template "headHTML" .}}
|
{{template "headHTML" .}}
|
||||||
<body>
|
<body>
|
||||||
{{template "headerHTML" .}}
|
{{template "headerHTML" .}}
|
||||||
|
|
||||||
<h2 class="w-title">{{.title}}</h2>
|
{{template "fullweatherHTML" .}}
|
||||||
<div class="weather-container">
|
|
||||||
{{range .weatherInfo}}
|
|
||||||
<div class="weather-w">
|
|
||||||
<h3>{{.Name}}</h3>
|
|
||||||
{{with index .Weather 0}}
|
|
||||||
<div class="weather-info">Opis: {{.Description}}</div>
|
|
||||||
{{end}}
|
|
||||||
<div class="weather-info">Temperatura: {{.Main.Temp}}°C</div>
|
|
||||||
<div class="weather-info">Osecaj: {{.Main.FellsLike}}°C</div>
|
|
||||||
<div class="weather-info">Pritisak:{{.Main.Preassure}} hPa</div>
|
|
||||||
<div class="weather-info">Vlaznost: {{.Main.Humidity}}%</div>
|
|
||||||
<div class="weather-info">Min Temp: {{.Main.TempMin}}°C</div>
|
|
||||||
<div class="weather-info">Max Temp: {{.Main.TempMax}}°C</div>
|
|
||||||
<div class="weather-info">Vetar: {{.Wind.Speed}} m/s</div>
|
|
||||||
<div class="weather-info">Oblaci: {{.Clouds.All}}%</div>
|
|
||||||
</div>
|
|
||||||
{{end}}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{{template "footerHTML" .}}
|
{{template "footerHTML" .}}
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user