diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..46154788 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,19 @@ +# Modified from .gitignore +node_modules +*.log +dist +.output +.nuxt +#.env # Not ignoring this file because it can contain build-related settings. +.DS_Store +.idea/ +.vite-inspect +.netlify/ +.eslintcache + +public/shiki +public/emojis + +*~ +*swp +*swo diff --git a/.env.example b/.env.example index a21e7f83..c3cc17d0 100644 --- a/.env.example +++ b/.env.example @@ -10,6 +10,8 @@ NUXT_CLOUDFLARE_API_TOKEN= NUXT_STORAGE_DRIVER= NUXT_STORAGE_FS_BASE= +NUXT_ADMIN_KEY= + NUXT_PUBLIC_DISABLE_VERSION_CHECK= NUXT_GITHUB_CLIENT_ID= diff --git a/.eslintignore b/.eslintignore index a5104c82..78bdfaee 100644 --- a/.eslintignore +++ b/.eslintignore @@ -3,5 +3,8 @@ *.ico *.toml *.patch +*.txt +public/ https-dev-config/localhost.crt https-dev-config/localhost.key +Dockerfile diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 8abe4458..4ef6738c 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1 +1,2 @@ -github: [antfu, patak-dev, sxzz, danielroe] +github: [elk-zone] +open_collective: elk diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 00000000..2189ced5 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,26 @@ + + +### Description + + + +### Additional context + + + +--- + +### What is the purpose of this pull request? + +- [ ] Bug fix +- [ ] New Feature +- [ ] Documentation update +- [ ] Translations update +- [ ] Other + +### Before submitting the PR, please make sure you do the following + +- [ ] Read the [Contributing Guidelines](https://github.com/elk-zone/elk/blob/main/CONTRIBUTING.md). +- [ ] Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate. +- [ ] Provide related snapshots or videos. +- [ ] Provide a description in this PR that addresses **what** the PR is solving, or reference the issue that it solves (e.g. `fixes #123`). diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a554d46f..3ed97488 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,5 +1,7 @@ name: ci +permissions: {} + on: push: branches: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e302c364..be309421 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,5 +1,8 @@ name: Release +permissions: + contents: write + on: push: tags: diff --git a/.npmrc b/.npmrc index e2ad808f..e4a0f0b7 100644 --- a/.npmrc +++ b/.npmrc @@ -1,3 +1,4 @@ shamefully-hoist=true strict-peer-dependencies=false shell-emulator=true +ignore-workspace-root-check=true diff --git a/.stackblitz/codeflow.json b/.stackblitz/codeflow.json new file mode 100644 index 00000000..21acb9d4 --- /dev/null +++ b/.stackblitz/codeflow.json @@ -0,0 +1,7 @@ +{ + "bot": { + "issues": { + "trigger": "all-issues" + } + } +} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 20a36e2a..31e43a9d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,9 +4,13 @@ Hi! We are really excited that you are interested in contributing to Elk. Before Refer also to https://github.com/antfu/contribute. -## Set up your local development environment +### Online -The package manager used to install and link dependencies must be [pnpm](https://pnpm.io/) (Note: on Linux in a standard Node 16+ environment, you should follow the instructions to install via Node's `corepack` rather than using the `curl` command). +You can use [StackBlitz Codeflow](https://stackblitz.com/codeflow) to fix bugs or implement features. You'll also see a Codeflow button on PRs to review them without a local setup. Once the elk repo has been cloned in Codeflow, the dev server will start automatically and print the URL to open the App. You should receive a prompt in the bottom-right suggesting to open it in the Editor or in another Tab. To learn more, check out the [Codeflow docs](https://developer.stackblitz.com/codeflow/what-is-codeflow). + +[![Open in Codeflow](https://developer.stackblitz.com/img/open_in_codeflow.svg)](https://pr.new/elk-zone/elk) + +### Local Setup To develop and test the Elk package: @@ -14,22 +18,37 @@ To develop and test the Elk package: 2. Ensure using the latest Node.js (16.x) -3. Elk uses pnpm v7, you must enable [Corepack](https://github.com/nodejs/corepack) by running `corepack enable`. +3. The package manager used to install and link dependencies must be [pnpm](https://pnpm.io/) v7. To use it you must first enable [Corepack](https://github.com/nodejs/corepack) by running `corepack enable`. (Note: on Linux in a standard Node 16+ environment, you should follow the instructions to install via Node's `corepack` rather than using the `curl` command) 4. Check out a branch where you can work and commit your changes: ```shell git checkout -b my-new-branch ``` -5. Run `pnpm i` in Elk's root folder +1. Run `pnpm i` in Elk's root folder -6. Run `pnpm nuxi prepare` in Elk's root folder +2. Run `pnpm nuxi prepare` in Elk's root folder -7. Run `pnpm dev` in Elk's root folder to start dev server or `pnpm dev:mocked` to start dev server with `@elkdev@universeodon.com` user. +3. Run `pnpm dev` in Elk's root folder to start dev server or `pnpm dev:mocked` to start dev server with `@elkdev@universeodon.com` user. + +We recommend installing [ni](https://github.com/antfu/ni#ni), that will use the right package manager in each of your projects. If `ni` is installed, you can instead run: + +``` +ni +nr dev +``` + +### Testing + +Elk uses [Vitest](https://vitest.dev). You can run the test suite with: + +``` +nr test +``` ### Running PWA on dev server -In order to run Elk with PWA enabled, run `pnpm run dev:pwa` in Elk's root folder to start dev server or `pnpm dev:mocked:pwa` to start dev server with `@elkdev@universeodon.com` user. +In order to run Elk with PWA enabled, run `pnpm dev:pwa` in Elk's root folder to start dev server or `pnpm dev:mocked:pwa` to start dev server with `@elkdev@universeodon.com` user. You should test the Elk PWA application on private browsing mode on any Chromium based browser: will not work on Firefox and Safari. @@ -44,7 +63,11 @@ If not using private browsing mode, you will need to uninstall the PWA applicati ## CI errors -Sometimes when you push your changes, the CI can fail, but we cannot check the logs to see what went wrong, run the following commands on your local environment: +Sometimes when you push your changes to create a new pull request (PR), the CI can fail, but we cannot check the logs to see what went wrong. + +If you are getting **Semantic Pull Request** error, please check the [Semantic Pull Request](https://www.conventionalcommits.org/en/v1.0.0/#summary) documentation. + +You can run the following commands on your local environment to fix CI errors: - `pnpm test:unit` to run unit tests, maybe you also need to update snapshots - `pnpm test:typecheck` to run TypeScript checks run on CI @@ -68,11 +91,11 @@ We are using [vue-i18n](https://vue-i18n.intlify.dev/) via [nuxt-i18n](https://i ### Adding a new language -1. Add a new file in [locales](../locales) folder with the language code as the filename. -2. Copy [en-US](../locales/en-US.json) and translate the strings. -3. Add the language to the `locales` array in [config/i18n.ts](../config/i18n.ts#L13) -4. If the language is `right-to-left`, add `dir` option with `rtl` value, for example, for [ar-EG](../config/i18n.ts#L63) -5. If the language requires special pluralization rules, add `pluralRule` callback option, for example, for [ar-EG](../config/i18n.ts#L64) +1. Add a new file in [locales](./locales) folder with the language code as the filename. +2. Copy [en-US](./locales/en-US.json) and translate the strings. +3. Add the language to the `locales` array in [config/i18n.ts](./config/i18n.ts#L12), below `en` variants and `ar-EG`. +4. If the language is `right-to-left`, add `dir` option with `rtl` value, for example, for [ar-EG](./config/i18n.ts#L27) +5. If the language requires special pluralization rules, add `pluralRule` callback option, for example, for [ar-EG](./config/i18n.ts#L27) Check [Pluralization rule callback](https://vue-i18n.intlify.dev/guide/essentials/pluralization.html#custom-pluralization) for more info. @@ -135,14 +158,14 @@ You can run this code in your browser console to see how it works: Either **{0}** or **{v}** should be used with the exception being custom plurals entries using the `{n}` placeholder. This is the full list of entries that will be available for number formatting in Elk: -- `action.boost_count` (no need to be included, we should use always `en-US` entry): `{0}` for formatted number and `{n}` for raw number - **{0} should be use** -- `action.favourite_count` (no need to be included, we should use always `en-US` entry): `{0}` for formatted number and `{n}` for raw number - **{0} should be use** -- `action.reply_count` (no need to be included, we should use always `en-US` entry): `{0}` for formatted number and `{n}` for raw number - **{0} should be use** -- `account.followers_count`: `{0}` for formatted number and `{n}` for raw number - **{0} should be use** -- `account.following_count`: `{0}` for formatted number and `{n}` for raw number - **{0} should be use** -- `account.posts_count`: `{0}` for formatted number and `{n}` for raw number - **{0} should be use** -- `compose.drafts`: `{v}` for formatted number and `{n}` for raw number - **{v} should be use** -- `notification.followed_you_count`: `{0}` for formatted number and `{n}` for raw number - **{0} should be use** -- `status.poll.count`: `{0}` for formatted number and `{n}` for raw number - **{0} should be use** -- `time_ago_options.*`: `{0}` for formatted number and `{n}` for raw number - **{0} should be use**: since numbers will be always small, we can also use `{n}` -- `timeline.show_new_items`: `{v}` for formatted number and `{n}` for raw number - **{v} should be use** +- `action.boost_count` (no need to be included, we should use always `en-US` entry): `{0}` for formatted number and `{n}` for raw number - **{0} should be used** +- `action.favourite_count` (no need to be included, we should use always `en-US` entry): `{0}` for formatted number and `{n}` for raw number - **{0} should be used** +- `action.reply_count` (no need to be included, we should use always `en-US` entry): `{0}` for formatted number and `{n}` for raw number - **{0} should be used** +- `account.followers_count`: `{0}` for formatted number and `{n}` for raw number - **{0} should be used** +- `account.following_count`: `{0}` for formatted number and `{n}` for raw number - **{0} should be used** +- `account.posts_count`: `{0}` for formatted number and `{n}` for raw number - **{0} should be used** +- `compose.drafts`: `{v}` for formatted number and `{n}` for raw number - **{v} should be used** +- `notification.followed_you_count`: `{0}` for formatted number and `{n}` for raw number - **{0} should be used** +- `status.poll.count`: `{0}` for formatted number and `{n}` for raw number - **{0} should be used** +- `time_ago_options.*`: `{0}` for formatted number and `{n}` for raw number - **{0} should be used**: since numbers will be always small, we can also use `{n}` +- `timeline.show_new_items`: `{v}` for formatted number and `{n}` for raw number - **{v} should be used** diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..f45aaf26 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,46 @@ +FROM docker.io/library/node:lts-alpine AS base + +# Prepare work directory +WORKDIR /elk + +FROM base AS builder + +# Prepare pnpm https://pnpm.io/installation#using-corepack +RUN corepack enable + +# Prepare deps +RUN apk update +RUN apk add git --no-cache + +# Prepare build deps ( ignore postinstall scripts for now ) +COPY package.json ./ +COPY pnpm-lock.yaml ./ +COPY patches ./patches +RUN pnpm i --frozen-lockfile --ignore-scripts + +# Copy all source files +COPY . ./ + +# Run full install with every postinstall script ( This needs project file ) +RUN pnpm i --frozen-lockfile + +# Build +RUN pnpm build + +FROM base AS runner + +ENV NODE_ENV=production + +COPY --from=builder /elk/.output ./.output + +EXPOSE 5314/tcp + +ENV PORT=5314 + +# Specify container only environment variables ( can be overwritten by runtime env ) +ENV NUXT_STORAGE_FS_BASE='/elk/data' + +# Persistent storage data +VOLUME [ "/elk/data" ] + +CMD ["node", ".output/server/index.mjs"] diff --git a/README.md b/README.md index 6693a9d6..7fb26c97 100644 --- a/README.md +++ b/README.md @@ -1,32 +1,55 @@ -# Elk -*A nimble Mastodon web client* -

- Elk logo + Elk logo

+ +

Elk alpha

+ +

+A nimble Mastodon web client +

+

discord chat Start new PR in StackBlitz Codeflow + Open board on Volta


-# Elk is in early alpha ⚠️ +

+ + Elk screenshots + +

-It is already quite usable, but it isn't ready for wide adoption yet. We recommend you to use if if you would like to help us building it. We appreciate your feedback and contributions. Check out the [Open Issues](https://github.com/elk-zone/elk/issues) and jump in the action. Join the [Elk discord server](https://chat.elk.zone) to chat with us and learn more about the project. +## ⚠️ Elk is in Alpha -The client is deployed on: +It is already quite usable, but it isn't ready for wide adoption yet. We recommend you use it if you would like to help us build it. We appreciate your feedback and contributions. Check out the [Open Issues](https://github.com/elk-zone/elk/issues) and jump in the action. Join the [Elk discord server](https://chat.elk.zone) to chat with us and learn more about the project. + +## Deployment + +### Official Deployment + +The Elk team maintains a deployment at: - 🦌 Production: [elk.zone](https://elk.zone) - 🐙 Canary: [main.elk.zone](https://main.elk.zone) (deploys on every commit to `main` branch) -You can share screenshots on social media but we prefer you avoid sharing this URL directly until the app is more polished. Feel free to share the URL with your friends and invite others you think could be interested in helping to improve Elk. +### Ecosystem -## Sponsors +These are known deployments using Elk as an alternative Web client for Mastodon servers or as a base for other projects in the fediverse: -We want to thanks the generous sponsoring and help of: +- [elk.h4.io](https://elk.h4.io) - Use Elk for the `h4.io` Server +- [elk.universeodon.com](https://elk.universeodon.com) - Use Elk for the Universeodon Server +- [elk.vmst.io](https://elk.vmst.io) - Use Elk for the `vmst.io` Server + +> **Note**: Community deployments are **NOT** maintained by the Elk team. It may not be synced with Elk's source code. Please do your own research about the host servers before using them. + +## 💖 Sponsors + +We are grateful for the generous sponsorship and help of: NuxtLabs @@ -37,7 +60,11 @@ We want to thanks the generous sponsoring and help of:

-And all the companies and individuals sponsoring Elk Team members. If you're enjoying the app, consider sponsoring our team: +And all the companies and individuals sponsoring Elk Team and the members. If you're enjoying the app, consider sponsoring us: + +- [Elk Team's GitHub Sponsors](https://github.com/sponsors/elk-zone) + +Or you can sponsor our core team members individually: - [Anthony Fu](https://github.com/sponsors/antfu) - [Daniel Roe](https://github.com/sponsors/danielroe) @@ -46,11 +73,11 @@ And all the companies and individuals sponsoring Elk Team members. If you're enj We would also appreciate sponsoring other contributors to the Elk project. If someone helps you solve an issue or implement a feature you wanted, supporting them would help make this project and OS more sustainable. -## Roadmap +## 📍 Roadmap [Open board on Volta](https://volta.net/elk-zone/elk) -## Contributing +## 🧑‍💻 Contributing We're really excited that you're interested in contributing to Elk! Before submitting your contribution, please read through the following guide. @@ -86,7 +113,7 @@ Elk uses [Vitest](https://vitest.dev). You can run the test suite with: nr test ``` -## Stack +## 🦄 Stack - [Vite](https://vitejs.dev/) - Next Generation Frontend Tooling - [Nuxt](https://nuxt.com/) - The Intuitive Web Framework @@ -100,6 +127,12 @@ nr test - [shiki](https://shiki.matsu.io/) - A beautiful Syntax Highlighter - [vite-plugin-pwa](https://github.com/vite-pwa/vite-plugin-pwa) - Prompt for update and push notifications -## License +## 👨‍💻 Contributors + + + + + +## 📄 License [MIT](./LICENSE) © 2022-PRESENT Elk contributors diff --git a/app.vue b/app.vue index 31cc43a1..3ce0a951 100644 --- a/app.vue +++ b/app.vue @@ -2,6 +2,16 @@ setupPageHeader() provideGlobalCommands() +const route = useRoute() + +if (process.server && !route.path.startsWith('/settings')) { + useHead({ + meta: [ + { property: 'og:url', content: `https://elk.zone${route.path}` }, + ], + }) +} + // We want to trigger rerendering the page when account changes const key = computed(() => `${currentUser.value?.server ?? currentServer.value}:${currentUser.value?.account.id || ''}`) diff --git a/components/account/AccountAvatar.vue b/components/account/AccountAvatar.vue index 4a4c50aa..26953d8d 100644 --- a/components/account/AccountAvatar.vue +++ b/components/account/AccountAvatar.vue @@ -15,9 +15,11 @@ const error = $ref(false) :key="account.avatar" width="400" height="400" - :src="error ? 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7' : account.avatar" + select-none + :src="(error || !loaded) ? 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7' : account.avatar" :alt="$t('account.avatar_description', [account.username])" loading="lazy" + class="account-avatar" :class="(loaded ? 'bg-base' : 'bg-gray:10') + (square ? ' ' : ' rounded-full')" :style="{ 'clip-path': square ? `url(#avatar-mask)` : 'none' }" v-bind="$attrs" diff --git a/components/account/AccountFollowButton.vue b/components/account/AccountFollowButton.vue index 5a39eaa0..7aab0fd9 100644 --- a/components/account/AccountFollowButton.vue +++ b/components/account/AccountFollowButton.vue @@ -8,18 +8,28 @@ const { account, command, context, ...props } = defineProps<{ command?: boolean }>() -const isSelf = $computed(() => currentUser.value?.account.id === account.id) +const { t } = useI18n() +const isSelf = $(useSelfAccount(() => account)) const enable = $computed(() => !isSelf && currentUser.value) const relationship = $computed(() => props.relationship || useRelationship(account).value) -const masto = useMasto() +const { client } = $(useMasto()) async function toggleFollow() { + if (relationship!.following) { + if (await openConfirmDialog({ + title: t('confirm.unfollow.title'), + confirm: t('confirm.unfollow.confirm'), + cancel: t('confirm.unfollow.cancel'), + }) !== 'confirm') + return + } relationship!.following = !relationship!.following try { - const newRel = await masto.v1.accounts[relationship!.following ? 'follow' : 'unfollow'](account.id) + const newRel = await client.v1.accounts[relationship!.following ? 'follow' : 'unfollow'](account.id) Object.assign(relationship!, newRel) } - catch { + catch (err) { + console.error(err) // TODO error handling relationship!.following = !relationship!.following } @@ -28,10 +38,11 @@ async function toggleFollow() { async function unblock() { relationship!.blocking = false try { - const newRel = await masto.v1.accounts.unblock(account.id) + const newRel = await client.v1.accounts.unblock(account.id) Object.assign(relationship!, newRel) } - catch { + catch (err) { + console.error(err) // TODO error handling relationship!.blocking = true } @@ -40,17 +51,16 @@ async function unblock() { async function unmute() { relationship!.muting = false try { - const newRel = await masto.v1.accounts.unmute(account.id) + const newRel = await client.v1.accounts.unmute(account.id) Object.assign(relationship!, newRel) } - catch { + catch (err) { + console.error(err) // TODO error handling relationship!.muting = true } } -const { t } = useI18n() - useCommand({ scope: 'Actions', order: -2, diff --git a/components/account/AccountHeader.vue b/components/account/AccountHeader.vue index 031c2573..e2779d21 100644 --- a/components/account/AccountHeader.vue +++ b/components/account/AccountHeader.vue @@ -6,6 +6,8 @@ const { account } = defineProps<{ command?: boolean }>() +const { client } = $(useMasto()) + const { t } = useI18n() const createdAt = $(useFormattedDateTime(() => account.createdAt, { @@ -14,13 +16,20 @@ const createdAt = $(useFormattedDateTime(() => account.createdAt, { year: 'numeric', })) +const relationship = $(useRelationship(account)) + const namedFields = ref([]) const iconFields = ref([]) +const hasHeader = $computed(() => !account.header.endsWith('/original/missing.png')) function getFieldIconTitle(fieldName: string) { return fieldName === 'Joined' ? t('account.joined') : fieldName } +function getNotificationIconTitle() { + return relationship?.notifying ? t('account.notifications_on_post_disable', { username: `@${account.username}` }) : t('account.notifications_on_post_enable', { username: `@${account.username}` }) +} + function previewHeader() { openMediaPreview([{ id: `${account.acct}:header`, @@ -39,6 +48,18 @@ function previewAvatar() { }]) } +async function toggleNotifications() { + relationship!.notifying = !relationship?.notifying + try { + const newRel = await client.v1.accounts.follow(account.id, { notify: relationship?.notifying }) + Object.assign(relationship!, newRel) + } + catch { + // TODO error handling + relationship!.notifying = !relationship?.notifying + } +} + watchEffect(() => { const named: mastodon.v1.AccountField[] = [] const icons: mastodon.v1.AccountField[] = [] @@ -59,19 +80,20 @@ watchEffect(() => { iconFields.value = icons }) -const isSelf = $computed(() => currentUser.value?.account.id === account.id) +const isSelf = $(useSelfAccount(() => account)) +const isNotifiedOnPost = $computed(() => !!relationship?.notifying) diff --git a/components/account/AccountPaginator.vue b/components/account/AccountPaginator.vue index ecb92d7d..86bcccb8 100644 --- a/components/account/AccountPaginator.vue +++ b/components/account/AccountPaginator.vue @@ -1,10 +1,19 @@ + diff --git a/components/account/AccountPostsFollowers.vue b/components/account/AccountPostsFollowers.vue index f2e1cbcc..d647bd62 100644 --- a/components/account/AccountPostsFollowers.vue +++ b/components/account/AccountPostsFollowers.vue @@ -4,6 +4,8 @@ import type { mastodon } from 'masto' defineProps<{ account: mastodon.v1.Account }>() + +const userSettings = useUserSettings() - diff --git a/components/common/CommonInputImage.vue b/components/common/CommonInputImage.vue index 595d5786..4a002ed2 100644 --- a/components/common/CommonInputImage.vue +++ b/components/common/CommonInputImage.vue @@ -88,17 +88,19 @@ watch(file, (image, _, onCleanup) => { w-full h-full > -
-
-
+ + + -
-
-
+ + + + diff --git a/components/common/CommonMask.vue b/components/common/CommonMask.vue new file mode 100644 index 00000000..a2f926ba --- /dev/null +++ b/components/common/CommonMask.vue @@ -0,0 +1,13 @@ + + + diff --git a/components/common/CommonPaginator.vue b/components/common/CommonPaginator.vue index 19f14677..2961a7e7 100644 --- a/components/common/CommonPaginator.vue +++ b/components/common/CommonPaginator.vue @@ -44,7 +44,7 @@ defineSlots<{ const { t } = useI18n() -const { items, prevItems, update, state, endAnchor, error } = usePaginator(paginator, stream, eventType, preprocess, context) +const { items, prevItems, update, state, endAnchor, error } = usePaginator(paginator, $$(stream), eventType, preprocess, context)