Selaa lähdekoodia

Fix GA template

Dima 1 vuosi sitten
vanhempi
commit
0eddd3bdd1

+ 5 - 5
internal/repositories/article.go

@@ -37,7 +37,7 @@ func (a articleRepository) GetAllPreview(ctx context.Context) ([]models.ArticleP
 		return nil, err
 	}
 
-	rows, err := a.db.QueryContext(ctx, query, args)
+	rows, err := a.db.QueryContext(ctx, query, args...)
 	if err != nil {
 		return nil, err
 	}
@@ -69,7 +69,7 @@ func (a articleRepository) GetAll(ctx context.Context) ([]models.Article, error)
 		OrderBy("publish_time DESC").
 		ToSql()
 
-	rows, err := a.db.QueryContext(ctx, query, args)
+	rows, err := a.db.QueryContext(ctx, query, args...)
 	if err != nil {
 		return nil, err
 	}
@@ -98,7 +98,7 @@ func (a articleRepository) GetPreviewByTagID(ctx context.Context, tagID int) ([]
 
 	query := "SELECT a.id, a.url, a.publish_time, a.title, a.preview_text, a.image " +
 		"FROM " + articleTableName + " a, " + articleTagTableName + " at " +
-		"WHERE a.is_active = true AND at.article_id = a.id AND at.tag_id = ? " +
+		"WHERE a.is_active = true AND at.article_id = a.id AND at.tag_id = $1 " +
 		"ORDER BY a.publish_time DESC"
 
 	rows, err := a.db.QueryContext(ctx, query, tagID)
@@ -129,7 +129,7 @@ func (a articleRepository) GetByURL(ctx context.Context, url string) (*models.Ar
 	var res models.Article
 
 	query, args, err := sq.Select("id", "url", "publish_time", "title", "image", "text", "preview_text", "meta_keywords", "meta_desc", "is_active").
-		From(tagTableName).
+		From(articleTableName).
 		PlaceholderFormat(sq.Dollar).
 		Where(sq.Eq{"url": url}).
 		Limit(1).
@@ -153,7 +153,7 @@ func (a articleRepository) GetByID(ctx context.Context, id int) (*models.Article
 	var res models.Article
 
 	query, args, err := sq.Select("id", "url", "publish_time", "title", "image", "text", "preview_text", "meta_keywords", "meta_desc", "is_active").
-		From(tagTableName).
+		From(articleTableName).
 		PlaceholderFormat(sq.Dollar).
 		Where(sq.Eq{"id": id}).
 		Limit(1).

+ 1 - 1
internal/repositories/tag.go

@@ -28,7 +28,7 @@ func (t tagRepository) GetAllUsed(ctx context.Context) ([]models.Tag, error) {
 
 	query := "SELECT t.id, t.url, t.tag " +
 		"FROM " + articleTagTableName + " at, " + tagTableName + " t " +
-		"WHERE t.id = at.tag_id AND at.article_id IN" +
+		"WHERE t.id = at.tag_id AND at.article_id IN " +
 		"(SELECT id FROM " + articleTableName + " " + "WHERE is_active = true) " +
 		"GROUP BY t.id"
 

+ 3 - 1
internal/templates/_ga.html

@@ -1,10 +1,12 @@
 {{ define "_ga" }}
+    {{ if ga }}
     <script>
         (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
             (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
             m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
         })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
-        ga('create', 'UA-61815600-2', 'auto');
+        ga('create', {{ ga }}, 'auto');
         ga('send', 'pageview');
     </script>
+    {{ end }}
 {{ end }}