Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add /feed urls to home, profile, community, and multicommunity.
- You can now go to any of the above pages, add `/feed` to the url, and
it will redirect to the correct back-end lemmy rss feed.
- Fixes #3215
  • Loading branch information
dessalines committed Jan 16, 2026
commit 1bfc4f46b464d30498f4a18faeb50de9d72ac46f
7 changes: 7 additions & 0 deletions src/server/handlers/community-feed-handler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { communityRSSUrlLocal } from "@utils/app";
import type { Request, Response } from "express";

export default async (req: Request, res: Response) => {
const name = req.params.name;
res.redirect(communityRSSUrlLocal(name));
};
6 changes: 6 additions & 0 deletions src/server/handlers/frontpage-feed-handler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { localRSSUrl } from "@utils/app";
import type { Response } from "express";

export default async ({ res }: { res: Response }) => {
res.redirect(localRSSUrl());
};
7 changes: 7 additions & 0 deletions src/server/handlers/multi-community-feed-handler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { multiCommunityRSSUrlLocal } from "@utils/app";
import type { Request, Response } from "express";

export default async (req: Request, res: Response) => {
const name = req.params.name;
res.redirect(multiCommunityRSSUrlLocal(name));
};
7 changes: 7 additions & 0 deletions src/server/handlers/profile-feed-handler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { profileRSSUrl } from "@utils/app";
import type { Request, Response } from "express";

export default async (req: Request, res: Response) => {
const name = req.params.name;
res.redirect(profileRSSUrl(name));
};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No need to make a separate file for each of these, just use src/server/handlers/feed-handlers.ts

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

K, will do shortly.

8 changes: 8 additions & 0 deletions src/server/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import cookieParser from "cookie-parser";
import { setupMarkdown } from "@utils/markdown";
import compression from "compression";
import { enableResponseBodyCompression } from "./utils/dev-env";
import FrontPageFeedHandler from "./handlers/frontpage-feed-handler";
import ProfileFeedHandler from "./handlers/profile-feed-handler";
import CommunityFeedHandler from "./handlers/community-feed-handler";
import MultiCommunityFeedHandler from "./handlers/multi-community-feed-handler";

const server = express();
server.use(cookieParser());
Expand Down Expand Up @@ -81,6 +85,10 @@ server.get("/manifest.webmanifest", ManifestHandler);
server.get("/css/themes/:name", ThemeHandler);
server.get("/css/code-themes/:name", CodeThemeHandler);
server.get("/css/themelist", ThemesListHandler);
server.get("/feed", FrontPageFeedHandler);
server.get("/u/:name/feed", ProfileFeedHandler);
server.get("/c/:name/feed", CommunityFeedHandler);
server.get("/m/:name/feed", MultiCommunityFeedHandler);
server.get("/{*splat}", CatchAllHandler);

const listener = server.listen(Number(port), hostname, () => {
Expand Down
13 changes: 7 additions & 6 deletions src/shared/components/home/home.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import {
allRSSUrl,
commentsToFlatNodes,
defaultPostListingMode,
editComment,
editPersonNotes,
editPost,
enableNsfw,
localRSSUrl,
mixedToCommentSortType,
mixedToPostSortType,
myAuth,
setIsoData,
showLocal,
subscribedRSSUrl,
updateCommunityBlock,
updatePersonBlock,
} from "@utils/app";
Expand Down Expand Up @@ -97,7 +100,7 @@ import { CommunityLink } from "../community/community-link";
import { PostListings } from "../post/post-listings";
import { SiteSidebar } from "./site-sidebar";
import { PaginatorCursor } from "../common/paginator-cursor";
import { getHttpBaseInternal, httpBackendUrl } from "@utils/env";
import { getHttpBaseInternal } from "@utils/env";
import {
CommentsLoadingSkeleton,
PostsLoadingSkeleton,
Expand Down Expand Up @@ -147,18 +150,16 @@ function getRss(listingType: ListingType, sort: PostSortType) {
const queryString = getQueryString({ sort });
switch (listingType) {
case "all": {
rss = httpBackendUrl("/feeds/all.xml" + queryString);
rss = allRSSUrl(queryString);
break;
}
case "local": {
rss = httpBackendUrl("/feeds/local.xml" + queryString);
rss = localRSSUrl(queryString);
break;
}
case "subscribed": {
const auth = myAuth();
rss = auth
? httpBackendUrl(`/feeds/front/${auth}.xml${queryString}`)
: undefined;
rss = auth ? subscribedRSSUrl(auth, queryString) : undefined;
break;
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/shared/components/person/notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
commentToFlatNode,
enableNsfw,
myAuth,
notificationsRSSUrl,
setIsoData,
updateCommunityBlock,
updatePersonBlock,
Expand Down Expand Up @@ -73,7 +74,7 @@ import { toast } from "@utils/app";
import { HtmlTags } from "../common/html-tags";
import { Icon, Spinner } from "../common/icon";
import { PrivateMessage } from "../private_message/private-message";
import { getHttpBaseInternal, httpBackendUrl } from "@utils/env";
import { getHttpBaseInternal } from "@utils/env";
import { CommentsLoadingSkeleton } from "../common/loading-skeleton";
import { RouteComponentProps } from "inferno-router/dist/Route";
import { IRoutePropsWithFetch } from "@utils/routes";
Expand Down Expand Up @@ -212,9 +213,7 @@ export class Notifications extends Component<

render() {
const auth = myAuth();
const notifsRss = auth
? httpBackendUrl(`/feeds/notifications/${auth}.xml`)
: undefined;
const notifsRss = auth ? notificationsRSSUrl(auth) : undefined;
return (
<div className="notifications container-lg">
<div className="row">
Expand Down
7 changes: 3 additions & 4 deletions src/shared/components/person/profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
enableNsfw,
getUncombinedPersonContent,
postViewToPersonContentCombinedView,
profileRSSUrl,
setIsoData,
updateCommunityBlock,
updatePersonBlock,
Expand Down Expand Up @@ -104,7 +105,7 @@ import { UserBadges } from "../common/user-badges";
import { CommunityLink } from "../community/community-link";
import { PersonDetails } from "./person-details";
import { PersonListing } from "./person-listing";
import { getHttpBaseInternal, httpBackendUrl } from "@utils/env";
import { getHttpBaseInternal } from "@utils/env";
import { IRoutePropsWithFetch } from "@utils/routes";
import { MediaUploads } from "../common/media-uploads";
import { cakeDate, futureDaysToUnixTime, nowBoolean } from "@utils/date";
Expand Down Expand Up @@ -888,9 +889,7 @@ export class Profile extends Component<ProfileRouteProps, ProfileState> {
const { sort, filter } = this.props;
const { username } = this.props.match.params;

const profileRss = httpBackendUrl(
`/feeds/u/${username}.xml${getQueryString({ sort })}`,
);
const profileRss = profileRSSUrl(username, sort);

return (
<div className="row align-items-center mb-3 g-3">
Expand Down
44 changes: 42 additions & 2 deletions src/shared/utils/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
PostListingMode,
MultiCommunity,
MultiCommunityView,
SearchSortType,
} from "lemmy-js-client";
import {
CommentNodeI,
Expand Down Expand Up @@ -132,7 +133,10 @@ export function commentToFlatNode(cv: CommentView): CommentNodeType {
return { view: { comment_view: cv, children: [], depth: 0 } };
}

export function communityRSSUrl(community: Community, sort: string): string {
export function communityRSSUrl(
community: Community,
sort: PostSortType = "new",
): string {
// Only add the domain for non-local
const domain = community.local ? "" : `@${hostname(community.ap_id)}`;

Expand All @@ -141,9 +145,14 @@ export function communityRSSUrl(community: Community, sort: string): string {
);
}

/** This is used for the /c/:name/feed endpoint only. **/
export function communityRSSUrlLocal(communityName: string) {
return httpBackendUrl(`/feeds/c/${communityName}.xml`);
}

export function multiCommunityRSSUrl(
multiCommunity: MultiCommunity,
sort: string,
sort: PostSortType = "new",
): string {
// Only add the domain for non-local
const domain = multiCommunity.local
Expand All @@ -153,6 +162,37 @@ export function multiCommunityRSSUrl(
return `/feeds/m/${multiCommunity.name}${domain}.xml${getQueryString({ sort })}`;
}

/** This is used for the /m/:name/feed endpoint only. **/
export function multiCommunityRSSUrlLocal(multiCommunityName: string) {
return httpBackendUrl(`/feeds/m/${multiCommunityName}.xml`);
}

export function allRSSUrl(queryString: string = ""): string {
return httpBackendUrl("/feeds/all.xml" + queryString);
}

export function localRSSUrl(queryString: string = ""): string {
return httpBackendUrl("/feeds/local.xml" + queryString);
}

export function subscribedRSSUrl(
auth: string,
queryString: string = "",
): string {
return httpBackendUrl(`/feeds/front/${auth}.xml${queryString}`);
}

export function profileRSSUrl(
username: string,
sort: SearchSortType = "new",
): string {
return httpBackendUrl(`/feeds/u/${username}.xml${getQueryString({ sort })}`);
}

export function notificationsRSSUrl(auth: string): string {
return httpBackendUrl(`/feeds/notifications/${auth}.xml`);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Better to define all this directly in the handler file, then its all in one place, easy to find and its not in the way here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Some of them are used elsewhere, and not used by the feed handler. So I wanted to keep all the RSS shortcuts together in one place.


export async function communitySearch(
text: string,
): Promise<CommunityTribute[]> {
Expand Down