Weather and Category

This commit is contained in:
2024-01-31 12:37:55 +01:00
parent f4a2251178
commit 232df1e4e0
24 changed files with 370 additions and 351 deletions

View File

@@ -4,4 +4,6 @@ DB_HOST =localhost
DB_PORT =5432
DB_USER =svevijesti
DB_PASSWORD =salmonela pljusti 221 hamo
DB_NAME =svevijestiweb
DB_NAME =svevijestiweb
API_KEY=abb35e21bdcbad6d1b00141a2b25cf5a

1
go.mod
View File

@@ -15,6 +15,7 @@ require (
github.com/gorilla/mux v1.8.0 // indirect
github.com/gosimple/slug v1.12.0 // 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/lib/pq v1.10.4 // indirect
github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca // indirect

2
go.sum
View File

@@ -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/unidecode v1.0.1 h1:hZzFTMMqSswvf0LBJZCZgThIZrpDHFXux9KeGmn6T/o=
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/go.mod h1:LGsjYYtgxbetdg5owWB2mpgUL6e2nfw2eObZ0u0qvak=
github.com/lib/pq v1.10.4 h1:SO9z7FRPzA03QhHKJrH5BXA6HU1rS4V2nIVrrNC1iYk=

View File

@@ -49,7 +49,7 @@ func ArticlesForDay(store *Store, day time.Time) (articles []model.DisplayArticl
result := []model.DisplayArticle{}
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 {
return result, err
@@ -68,7 +68,7 @@ func ArticlesForDay(store *Store, day time.Time) (articles []model.DisplayArticl
for rows.Next() {
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 {
return result, err
}
@@ -96,7 +96,7 @@ func ArticleByID(store *Store, ID int, slug string) (article model.DisplayArticl
result := model.DisplayArticle{}
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 {
return result, err
@@ -110,7 +110,7 @@ func ArticleByID(store *Store, ID int, slug string) (article model.DisplayArticl
r := model.DisplayArticle{}
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 {
return result, err
}
@@ -139,7 +139,7 @@ func PreviousAndNextArticleUrlByID(store *Store, ID int) (nextUrl string, previo
nextResult, previousResult := "#", "#"
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 {
fmt.Println("Err 1:", err)
@@ -155,7 +155,7 @@ func PreviousAndNextArticleUrlByID(store *Store, ID int) (nextUrl string, previo
r := model.DisplayArticle{}
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 {
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)
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 {
fmt.Println("Err 1:", err)
@@ -178,7 +178,7 @@ func PreviousAndNextArticleUrlByID(store *Store, ID int) (nextUrl string, previo
}
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 {
fmt.Println("Err 4:", err)
return nextResult, previousResult, err
@@ -187,48 +187,3 @@ func PreviousAndNextArticleUrlByID(store *Store, ID int) (nextUrl string, previo
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
}

View File

@@ -25,11 +25,25 @@ func rootHandler(wr http.ResponseWriter, req *http.Request) {
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{}{
"title": title,
"articles": articles,
"previous": dayBefore,
"next": "/",
"title": title,
"articles": articles,
"previous": dayBefore,
"next": "/",
"weatherInfo": weatherInfo,
"categories": CategoryMenu,
}
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)
}
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{}{
"title": title,
"articles": articles,
"previous": dayBefore,
"next": dayAfter,
"title": title,
"articles": articles,
"previous": dayBefore,
"next": dayAfter,
"weatherInfo": weatherInfo,
}
err = templates.ExecuteTemplate(wr, "homeHTML", data)
@@ -98,10 +125,11 @@ func articleHandler(wr http.ResponseWriter, req *http.Request) {
title := article.Title
data := map[string]interface{}{
"title": title,
"article": article,
"previous": previous,
"next": next,
"title": title,
"article": article,
"previous": previous,
"next": next,
"categories": CategoryMenu,
}
err = templates.ExecuteTemplate(wr, "articleHTML", data)

View File

@@ -4,31 +4,65 @@ import (
"net/http"
"time"
"github.com/gorilla/mux"
"gitlab.com/kbr4/svevijesti/internal/database"
"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()
if err != nil {
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)
for _, article := range articles {
articlesByCategory[article.Category] = append(articlesByCategory[article.Category], article)
}
for category, articles := range articlesByCategory {
data := map[string]interface{}{"Category": category, "Articles": articles}
err := templates.ExecuteTemplate(wr, "categoryHTML", data)
if err != nil {
panic(err)
}
var categories []string
for cat := range articlesByCategory {
categories = append(categories, cat)
}
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
}
}

View File

@@ -44,6 +44,6 @@ func CreateRoutes() *mux.Router {
r.HandleFunc("/{id:[0-9]+}/{slug}", articleHandler)
r.HandleFunc("/", rootHandler)
r.HandleFunc("/weather", WeatherHandler)
r.HandleFunc("/{category}", categoryHandler)
r.HandleFunc("/{category}", handleCategory)
return r
}

View File

@@ -5,9 +5,27 @@ import (
"fmt"
"io/ioutil"
"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 {
Coord struct {
@@ -74,24 +92,13 @@ func WeatherHandler(w http.ResponseWriter, r *http.Request) {
data := map[string]interface{}{
"title": title,
"weatherInfo": weatherInfo,
"categories": CategoryMenu,
}
err := templates.ExecuteTemplate(w, "fullweatherHTML", data)
err := templates.ExecuteTemplate(w, "weatherHTML", data)
if err != nil {
fmt.Println("Error executing template:", err)
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
}
}
}

View File

@@ -123,6 +123,15 @@ if __name__ == '__main__':
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:
title_text = slice_title_if_needed(title_text)
try:
@@ -146,9 +155,10 @@ if __name__ == '__main__':
else:
category = 'other'
category = category_translation.get(category, category.capitalize())
vector = embeddings.embed_query(generated_text)
print(f"Title: {title}")
print(f"Category: {category}")
if not is_similar_data(title, text, link, vector, threshold=0.98):

View File

@@ -1,17 +1,5 @@
{{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}}
<article class="news-article">
<div class="article_content">
@@ -22,9 +10,9 @@
</div>
</div>
<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>
<div class="timestamp"> starenovine - {{ .FormatedCreatedAt }}</div>
<div class="timestamp"> starenovine - {{ .FormatedCreatedAt }} - {{.Category}}</div>
</article>
{{else}}
<div class="empty">
@@ -34,49 +22,18 @@
</div>
<script>
let i = 1;
let allArticles = []
let lastArticles = []
let previewDivs = document.querySelectorAll('.prewi');
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();
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}}

View 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}}

View 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}}

View File

@@ -1,13 +1,33 @@
{{define "footerHTML"}}
<center><div class="sign">SN</div></center>
<footer>
<center>
<nav class="fot">
<a href="{{.previous}}">&lt;----</a> |
<a href="/">Početna</a> |
<a href="{{.next}}">----&gt;</a>
</nav>
<br>
<nav class="hed">
<a href="{{.previous}}">
<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="{{.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>
</footer>
{{end}}

23
web/data/fullweather.html Normal file
View 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}}

View File

@@ -25,7 +25,7 @@
}
body {
font-size: 1.5em;
font-size: 1.2em;
margin: 0 auto;
overflow-x: hidden;
background-color: black;
@@ -159,14 +159,11 @@ h1#title {
.hed {
background-color: #0B173B;
text-decoration: none;
color: white;
border-radius: 5px;
display: flex;
justify-content: center;
align-items: center;
padding-top: 5px;
padding-bottom: 5px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
gap: 5%;
transition: background-color 0.5s var(--ease);
@@ -187,7 +184,6 @@ h1#title {
gap: 10px;
text-decoration: none;
}
.article_content > a {
color: white;
text-decoration: none;
@@ -266,14 +262,78 @@ pre.article_content {
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) {
#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 {
display: grid;
margin-bottom: 4%;
}
.weather-widget {
width: 90vw;
height: 20px;
@@ -303,8 +363,8 @@ html {
}
.arr-pr-nx svg {
width: 60px;
height: 60px;
width: 40px;
height: 40px;
margin: 0 1rem;
cursor: pointer;
overflow: visible;
@@ -359,8 +419,8 @@ html {
display: flex;
justify-content: center;
align-items: center;
width: 60px;
height: 60px;
width: 40px;
height: 40px;
background-color: #0B173B;
border-radius: 50%;
cursor: pointer;
@@ -381,8 +441,6 @@ html {
color: #FF0000;
}
</style>
</head>
{{end}}

View File

@@ -14,49 +14,9 @@
</pre>
</a>
</center>
<nav class="hed">
<a href="{{.previous}}">
<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;
{{template "categorymenuHTML" .}}
if (top >= headerBottom) {
header.classList.add('fixed');
} else {
header.classList.remove('fixed');
}
}
window.addEventListener('scroll', handleScroll);
</script>
</br>
</header>
{{end}}

View File

@@ -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}}

View 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}}

View File

@@ -4,8 +4,7 @@
<body>
{{template "headerHTML" .}}
{{template "weatherHTML"}}
{{template "weatherwidgetHTML"}}
{{template "singleArticleHTML" .}}

View File

@@ -4,43 +4,8 @@
<body>
{{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" .}}
</body>
</html>

View File

@@ -4,7 +4,7 @@
<body>
{{template "headerHTML" .}}
{{template "weatherHTML"}}
{{template "weatherwidgetHTML"}}
{{template "articlesHTML" .}}

View File

@@ -1,10 +1,9 @@
{{define "homeHTML"}}
{{template "headHTML" .}}
<body>
{{template "headerHTML" .}}
{{template "weatherHTML"}}
{{template "weatherwidgetHTML" .}}
{{template "articlesHTML" .}}

View File

@@ -1,28 +1,10 @@
{{define "fullweatherHTML"}}
{{define "weatherHTML"}}
{{template "headHTML" .}}
<body>
{{template "headerHTML" .}}
<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>
{{template "fullweatherHTML" .}}
{{template "footerHTML" .}}
</body>