mirror of
https://github.com/sergeyyarkov/yarkov.tech.git
synced 2026-10-11 10:29:21 +03:00
views counter fix
This commit is contained in:
parent
cb8d5b3c6a
commit
2b0adea120
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"githubPullRequests.ignoredPullRequestBranches": ["develop"]
|
||||
}
|
||||
@ -1,12 +1,12 @@
|
||||
---
|
||||
import type { CollectionEntry } from "astro:content";
|
||||
import { Icon } from "astro-icon";
|
||||
import slugify from "@sindresorhus/slugify";
|
||||
import { createDateFormatter } from "@root/utils";
|
||||
import ArticleCover from "@components/ArticleCover.astro";
|
||||
import ArticleComments from "@components/ArticleComments.astro";
|
||||
import TranslatedLink from "@components/TranslatedLink.astro";
|
||||
import { useTranslation, getLanguageFromURL } from "@i18n/utils";
|
||||
import * as utils from "@utils/index";
|
||||
|
||||
export type Props = {
|
||||
article: CollectionEntry<"blog">;
|
||||
@ -17,9 +17,11 @@ const { article } = Astro.props as Props;
|
||||
const pageLang = getLanguageFromURL(Astro.url.pathname);
|
||||
const canonicalUrl = new URL(Astro.url.pathname, Astro.site);
|
||||
const {
|
||||
id,
|
||||
data: { coverImage, title, author, description, tags, pubDate },
|
||||
} = article;
|
||||
const slug = slugify(title, { lowercase: true });
|
||||
|
||||
const slug = utils.encodeString(id.split("/")[1]);
|
||||
const t = useTranslation(Astro);
|
||||
---
|
||||
|
||||
@ -68,6 +70,7 @@ const t = useTranslation(Astro);
|
||||
|
||||
<script define:vars={{ slug, IS_DEV: import.meta.env.DEV }}>
|
||||
(async () => {
|
||||
console.log(slug);
|
||||
if (IS_DEV) return;
|
||||
const response = await fetch(`/api/views?slug=${slug}`, { method: "POST" });
|
||||
if (!response.ok) return;
|
||||
|
||||
@ -15,3 +15,11 @@ export function isURL(url: string): boolean {
|
||||
export function findDuplicates(array: string[]): string[] {
|
||||
return array.filter((item, i) => array.indexOf(item) !== i);
|
||||
}
|
||||
|
||||
export function encodeString(string: string, slice: number = 10) {
|
||||
return Buffer.from(string)
|
||||
.toString("base64")
|
||||
.slice(0, slice)
|
||||
.toLocaleLowerCase()
|
||||
.replace(/[^a-zA-Z]+/g, "");
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user