Skip to content

Commit

Permalink
Resolved merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
vermakhushboo committed Nov 15, 2023
2 parents 1927332 + c8d3e2f commit 399b6ed
Show file tree
Hide file tree
Showing 33 changed files with 307 additions and 143 deletions.
2 changes: 1 addition & 1 deletion src/lib/components/MobileNav.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
href="https://github.com/appwrite/appwrite/stargazers"
target="_blank"
rel="noopener noreferrer"
class="aw-button is-text u-width-full-line"
class="aw-button is-text aw-u-inline-width-100-percent-mobile"
>
<span class="aw-icon-star" aria-hidden="true" />
<span class="text">Star on GitHub</span>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/Select.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
{/if}

<div
class="aw-select is-colored aw-is-only-mobile"
class="aw-select is-colored aw-is-only-mobile aw-u-inline-width-100-percent-mobile-break1"
style:display={nativeMobile ? undefined : 'none'}
>
{#if selectedOption?.icon}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/layouts/Docs.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
</a>
</div>
<div class="aw-mobile-header-end">
<a href="https://cloud.appwrite.io/console" class="aw-button is-not-mobile">
<a href="https://cloud.appwrite.io/console" class="aw-button aw-is-only-desktop">
<span class="aw-sub-body-500">Go to console</span>
</a>
<button on:click={toggleSidenav} class="aw-button is-text" aria-label="open navigation">
Expand Down
2 changes: 1 addition & 1 deletion src/lib/layouts/DocsArticle.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
use:scrollToTop
>
<span class="aw-icon-arrow-up" aria-hidden="true" />
<span class="aw-sub-body-500">Back to top</span>
<span class="aw-caption-400">Back to top</span>
</button>
</div>
{/if}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/layouts/DocsTutorial.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
<div class="u-sep-block-start u-padding-block-start-20">
<button class="aw-link u-inline-flex u-cross-center u-gap-8" use:scrollToTop>
<span class="aw-icon-arrow-up" aria-hidden="true" />
<span class="aw-sub-body-500">Back to top</span>
<span class="aw-caption-400">Back to top</span>
</button>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/lib/layouts/Sidebar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@
</button>
{/if}
<div class="aw-side-nav-mobile-footer-buttons">
<button class="aw-button u-width-full-line">
<button class="aw-button aw-u-inline-width-100-percent-mobile">
<span class="text">Go to console</span>
</button>

<a
href="https://github.com/appwrite/appwrite/stargazers"
target="_blank"
rel="noopener noreferrer"
class="aw-button is-text u-width-full-line"
class="aw-button is-text aw-u-inline-width-100-percent-mobile"
>
<span class="aw-icon-star" aria-hidden="true" />
<span class="text">Star on GitHub</span>
Expand Down
16 changes: 1 addition & 15 deletions src/markdoc/layouts/Author.svelte
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@
<script context="module" lang="ts">
export type AuthorData = {
name: string;
slug: string;
role: string;
avatar: string;
bio: string;
twitter: string;
linkedin: string;
github: string;
href: string;
};
</script>

<script lang="ts">
import { Article, FooterNav, MainFooter } from '$lib/components';
import { page } from '$app/stores';
import { Main } from '$lib/layouts';
import { getContext } from 'svelte';
import type { PostsData } from './Post.svelte';
import { BLOG_TITLE_SUFFIX } from '$routes/titles';
import type { PostsData, AuthorData } from '$routes/blog/content';
import { DEFAULT_HOST } from '$lib/utils/metadata';
import FloatingHead from '$lib/components/FloatingHead.svelte';
Expand Down
11 changes: 1 addition & 10 deletions src/markdoc/layouts/Category.svelte
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
<script context="module" lang="ts">
export type CategoryData = {
name: string;
description: string;
href: string;
};
</script>

<script lang="ts">
import { Article, FooterNav, MainFooter } from '$lib/components';
import { Main } from '$lib/layouts';
import { getContext } from 'svelte';
import type { PostsData } from './Post.svelte';
import type { AuthorData } from './Author.svelte';
import type { PostsData, AuthorData } from '$routes/blog/content';
import { BLOG_TITLE_SUFFIX } from '$routes/titles';
import { DEFAULT_HOST } from '$lib/utils/metadata';
Expand Down
17 changes: 1 addition & 16 deletions src/markdoc/layouts/Post.svelte
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@
<script context="module" lang="ts">
export type PostsData = {
title: string;
description: string;
date: Date;
cover: string;
timeToRead: number;
author: string;
category: string;
href: string;
featured?: boolean;
};
</script>

<script lang="ts">
import { Article, FooterNav, MainFooter, Newsletter } from '$lib/components';
import { Main } from '$lib/layouts';
import { getContext } from 'svelte';
import type { AuthorData } from './Author.svelte';
import type { CategoryData } from './Category.svelte';
import type { CategoryData, AuthorData, PostsData } from '$routes/blog/content';
import { BLOG_TITLE_SUFFIX } from '$routes/titles';
import { DEFAULT_HOST } from '$lib/utils/metadata';
Expand Down
78 changes: 6 additions & 72 deletions src/routes/blog/+layout.ts
Original file line number Diff line number Diff line change
@@ -1,75 +1,9 @@
import { base } from '$app/paths';
import type { AuthorData } from '$markdoc/layouts/Author.svelte';
import type { CategoryData } from '$markdoc/layouts/Category.svelte';
import type { PostsData } from '$markdoc/layouts/Post.svelte';
import { posts, authors, categories } from './content';

export function load() {
const postsGlob = import.meta.glob('./post/**/*.markdoc', {
eager: true
});
const authorsGlob = import.meta.glob('./author/**/*.markdoc', {
eager: true
});
const categoriesGlob = import.meta.glob('./category/**/*.markdoc', {
eager: true
});

const posts = Object.entries(postsGlob)
.map(([filepath, postList]) => {
const { frontmatter } = postList as {
frontmatter: PostsData;
};
const slug = filepath.replace('./', '').replace('/+page.markdoc', '');
const postName = slug.slice(slug.lastIndexOf('/') + 1);

return {
title: frontmatter.title,
description: frontmatter.description,
date: new Date(frontmatter.date),
cover: frontmatter.cover,
timeToRead: frontmatter.timeToRead,
author: frontmatter.author,
category: frontmatter.category,
href: `${base}/blog/post/${postName}`
};
})
.sort((a, b) => {
return b.date.getTime() - a.date.getTime();
});

const authors = Object.values(authorsGlob).map((authorList) => {
const { frontmatter } = authorList as {
frontmatter: AuthorData;
};

return {
name: frontmatter.name,
slug: frontmatter.slug,
role: frontmatter.role,
avatar: frontmatter.avatar,
bio: frontmatter.bio,
twitter: frontmatter.twitter,
linkedin: frontmatter.linkedin,
github: frontmatter.github,
href: `${base}/blog/author/${frontmatter.slug}`
};
});

const categories = Object.values(categoriesGlob).map((categoryList) => {
const { frontmatter } = categoryList as {
frontmatter: CategoryData;
};

return {
name: frontmatter.name,
description: frontmatter.description,
href: `${base}/blog/category/${frontmatter.name.toLowerCase()}`
};
});

return {
posts,
authors,
categories
};
return {
posts,
authors,
categories
};
}
11 changes: 11 additions & 0 deletions src/routes/blog/author/luke-silver/+page.markdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
layout: author
slug: luke-silver
name: Luke B. Silver
role: Software Engineer
bio: Building integrations with and on Appwrite
avatar: /images/avatars/luke.png
twitter: https://twitter.com/lukebsilver
github: https://github.com/loks0n
linkedin: https://www.linkedin.com/in/lukebsilver/
---
91 changes: 91 additions & 0 deletions src/routes/blog/content.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { base } from '$app/paths';
export type CategoryData = {
name: string;
description: string;
href: string;
};
export type AuthorData = {
name: string;
slug: string;
role: string;
avatar: string;
bio: string;
twitter: string;
linkedin: string;
github: string;
href: string;
};
export type PostsData = {
title: string;
description: string;
date: Date;
cover: string;
timeToRead: number;
author: string;
category: string;
href: string;
featured?: boolean;
};

const postsGlob = import.meta.glob('./post/**/*.markdoc', {
eager: true
});
const authorsGlob = import.meta.glob('./author/**/*.markdoc', {
eager: true
});
const categoriesGlob = import.meta.glob('./category/**/*.markdoc', {
eager: true
});

export const posts = Object.entries(postsGlob)
.map(([filepath, postList]) => {
const { frontmatter } = postList as {
frontmatter: PostsData;
};
const slug = filepath.replace('./', '').replace('/+page.markdoc', '');
const postName = slug.slice(slug.lastIndexOf('/') + 1);

return {
title: frontmatter.title,
description: frontmatter.description,
date: new Date(frontmatter.date),
cover: frontmatter.cover,
timeToRead: frontmatter.timeToRead,
author: frontmatter.author,
category: frontmatter.category,
href: `${base}/blog/post/${postName}`
};
})
.sort((a, b) => {
return b.date.getTime() - a.date.getTime();
});

export const authors = Object.values(authorsGlob).map((authorList) => {
const { frontmatter } = authorList as {
frontmatter: AuthorData;
};

return {
name: frontmatter.name,
slug: frontmatter.slug,
role: frontmatter.role,
avatar: frontmatter.avatar,
bio: frontmatter.bio,
twitter: frontmatter.twitter,
linkedin: frontmatter.linkedin,
github: frontmatter.github,
href: `${base}/blog/author/${frontmatter.slug}`
};
});

export const categories = Object.values(categoriesGlob).map((categoryList) => {
const { frontmatter } = categoryList as {
frontmatter: CategoryData;
};

return {
name: frontmatter.name,
description: frontmatter.description,
href: `${base}/blog/category/${frontmatter.name.toLowerCase()}`
};
});
12 changes: 12 additions & 0 deletions src/routes/blog/feed.json/+server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { RequestHandler } from './$types';
import { posts } from '../content';
import { json } from '@sveltejs/kit';

export const prerender = true;

export const GET: RequestHandler = () => {
return json({
posts,
total: Object.keys(posts).length
});
};
60 changes: 60 additions & 0 deletions src/routes/blog/post/adding-url-shortener-function/+page.markdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
layout: post
title: Add a URL shortener function to your application
description: Learning how to add the URL shortener function template to your application.
cover: /images/blog/adding-url-shortener/cover.png
timeToRead: 5
date: 2023-11-08
author: haimantika-mitra
category: functions
featured: false
---

Appwrite Functions are user-defined functions that can start small and scale big, deploying automatically from source control. With the introduction of function templates, you can quickly add new integrations into your app without writing additional code or managing infrastructure. Function templates are pre-built Appwrite Functions that can be integrated into your Appwrite project with just a few clicks.

A URL shortener takes a long or complex URL and generates a shorter, more concise version. The primary purpose of a URL shortener function is to make links easier to share, manage, and remember.
For e.g https://dev.to/appwrite/introducing-appwrite-migrations-effortless-data-migration-from-your-platforms-5dhh to http://tinyurl.com/bd5usb3n

In this blog, we’ll learn to build a URL shortener using Appwrite Functions template. The template benefits from the built-in scalability, reliability, and security of Appwrite Functions.

You can find the source code on our [templates GitHub repository](https://github.com/appwrite/templates/tree/main/node/url-shortener).

# Setting up the Template
To get started, you need to navigate to the functions page on the **[Appwrite](https://appwrite.io/cloud)** console. From there, we will select the **Templates** tab, search for and select the **URL Shortener** function template.

![Function template](/images/blog/adding-url-shortener/functions.png)

The function requires two variables:
- `APPWRITE_API_KEY`
- `SHORT_BASE_URL`

![Required variables](/images/blog/adding-url-shortener/variables.png)

Once you have populated those, you can go straight to the **Connect** step.

![Connecting repository](/images/blog/adding-url-shortener/connect.png)

Select **Create a new repository** (this will generate a GitHub repository for you with the function), and leave the production branch and root settings as default to create this function.

# Using the Function

Visit the **Domains** tab on the function page and copy the domain URL to test the function.

![Domains](/images/blog/adding-url-shortener/shortener.png)

Go to the function URL in your web browser, and you'll see a short url like the one shown below.

# Next Steps

URL shorteners often offer additional features such as tracking click-through rates, providing analytics on link usage, and allowing users to customize the shortened URL to some extent.This Function Template can be extended to perform a lot of functionalities. Some examples are:

1. **Link Analytics and Tracking:** Enhance the URL shortener to track click-through rates, geographical location of users, referral sources, and other analytics data. This could provide valuable insights into the popularity and effectiveness of shared links.
2. **Link Management Dashboard:** Create a user-friendly dashboard where users can manage their shortened links, view statistics, and perform various actions on their links.

Be sure to check out the other available Function Templates. We’ve created many that could be of use in your projects. You can find the [templates GitHub repository here](https://github.com/appwrite/templates).

For more information about Appwrite and Appwrite Functions:

1. **[Appwrite Function Docs](https://appwrite.io/docs/functions)**: These documents provide more information on how to use Appwrite Functions.
2. **[Functions Announcement](https://dev.to/appwrite/serverless-your-way-unleashing-appwrite-functions-true-potential-2l4f)**: Read the full announcement on Functions 1.4.
3. **[Appwrite Discord](https://discord.com/invite/appwrite)**: Connect with other developers and the Appwrite team for discussion, questions, and collaboration.
Loading

0 comments on commit 399b6ed

Please sign in to comment.