Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Change blog to tutorials #3713

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<NuxtLink :to="webflowItem.url" target="_blank">
<NuxtLink :to="webflowItem.url" target="_blank" @click="trackClick">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were you able to test this to make sure the to doesn't interrupt the tracking call?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah because it opens in a new tab it doesn't intervere, original tab stays open and emits the event :)

<div
class="bg-foundation border border-outline-3 rounded-xl flex flex-col overflow-hidden hover:border-outline-5 transition"
>
Expand All @@ -17,33 +17,29 @@
>
<HeaderLogoBlock no-link minimal class="scale-150" />
</div>
<div class="p-5 pb-4">
<div class="p-5">
<h3 class="text-body-2xs text-foreground truncate">
{{ webflowItem.title }}
</h3>
<p class="text-body-3xs text-foreground-2 mt-2">
<span v-tippy="createdOn.full">
{{ createdOn.relative }}
</span>
<template v-if="webflowItem.readTime">
<span class="pl-1 pr-2">•</span>
{{ webflowItem.readTime }}m read
</template>
</p>
</div>
</div>
</NuxtLink>
</template>

<script lang="ts" setup>
import type { WebflowItem } from '~/lib/dashboard/helpers/types'
import { useMixpanel } from '~~/lib/core/composables/mp'

const mixpanel = useMixpanel()

const props = defineProps<{
webflowItem: WebflowItem
}>()

const createdOn = computed(() => ({
full: formattedFullDate(props.webflowItem.createdOn),
relative: formattedRelativeDate(props.webflowItem.createdOn, { capitalize: true })
}))
const trackClick = () => {
mixpanel.track('Tutorial clicked', {
title: props.webflowItem.title,
id: props.webflowItem.id
})
}
</script>
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<template>
<section v-if="!error">
<h2 class="text-heading-sm text-foreground-2 mb-4">Blog</h2>
<h2 class="text-heading-sm text-foreground-2 mb-4">Tutorials</h2>
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4">
<DashboardBlogCard
<DashboardTutorialsCard
v-for="webflowItem in webflowItems"
:key="webflowItem.id"
:webflow-item="webflowItem"
Expand Down
1 change: 0 additions & 1 deletion packages/frontend-2/lib/dashboard/helpers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export type WebflowItem = {
lastPublished: string
featureImageUrl?: string
url: string
readTime?: number
}

export type QuickStartItem = {
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend-2/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
</div>
</section>
</div>
<DashboardBlogWrapper />
<DashboardTutorialsWrapper />
</div>

<ProjectsAddDialog v-model:open="openNewProject" />
Expand Down
13 changes: 2 additions & 11 deletions packages/frontend-2/server/api/webflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ type WebflowApiResponse = {
}>
}

const calculateReadTime = (content: string): number => {
const wordsPerMinute = 280
const wordCount = content.trim().split(/\s+/).length
return Math.ceil(wordCount / wordsPerMinute)
}

// Used to filter to last 6 months' articles to prevent old,
// recently edited posts from appearing at the top
const getSixMonthsAgo = (): Date => {
Expand All @@ -41,7 +35,7 @@ export default defineEventHandler(async (): Promise<{ items: WebflowItem[] }> =>
}

const url =
'https://api.webflow.com/v2/collections/66d822d3199be6f73a6c3c2c/items?limit=16&sortBy=lastPublished&sortOrder=desc'
'https://api.webflow.com/v2/collections/66d79d1c9cdda972d5c718b4/items?limit=16&sortBy=lastPublished&sortOrder=desc'

try {
const response = await fetch(url, {
Expand Down Expand Up @@ -77,10 +71,7 @@ export default defineEventHandler(async (): Promise<{ items: WebflowItem[] }> =>
createdOn: item.createdOn,
lastPublished: item.lastPublished,
featureImageUrl: item.fieldData['feature-image']?.url,
url: `https://speckle.systems/blog/${item.fieldData.slug}`,
readTime: item.fieldData.html
? calculateReadTime(item.fieldData.html)
: undefined
url: `https://speckle.systems/tutorials/${item.fieldData.slug}`
})
)
}
Expand Down