Skip to content
Merged

Dev #81

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
6 changes: 6 additions & 0 deletions bruno/bruno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"version": "1",
"name": "bruno",
"type": "collection",
"ignore": ["node_modules", ".git"]
}
4 changes: 4 additions & 0 deletions bruno/collection.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
meta {
name: bruno
type: collection
}
27 changes: 27 additions & 0 deletions bruno/query-posts.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
meta {
name: Query Posts
type: http
seq: 1
}

post {
url: http://localhost:4321/api/posts
body: json
auth: none
}

body:json {
{
"filter": {
"keyword": "scouting"
},
"sort": {
"mode": "date",
"direction": "desc"
},
"paginate": {
"page": 1,
"pageSize": 20
}
}
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@
"@fortawesome/free-brands-svg-icons": "^7.2.0",
"@fortawesome/free-solid-svg-icons": "^7.2.0",
"@fortawesome/react-fontawesome": "^0.2.0",
"@nanostores/persistent": "^1.3.3",
"@tailwindcss/vite": "^4.2.1",
"@upstash/redis": "^1.36.4",
"astro": "^6.0.3",
"feedsmith": "2.9.0",
"he": "^1.2.0",
"nanostores": "^1.1.1",
"react": "^19.2.4",
"react-dom": "^19.2.4",
"tailwindcss": "^4.2.1",
Expand Down
22 changes: 22 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions public/xslt/opml.xslt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,26 @@
<xsl:value-of select="head/title" />
</title>
<link rel="stylesheet" href="https://www.xml.style/css/water.min.css" />
<script>
window.addEventListener('load', function() {
var viewPara = document.getElementById("viewpara");
viewPara.style.display = "block";
var viewUrl = document.getElementById("viewUrl");
viewUrl.value = window.location.href;
});
</script>
</head>
<body>
<h1>
<xsl:value-of select="head/title" />
</h1>
<p id="viewpara" style="display:none;">
<form method="get" action="https://opml-viewer.fileformat.info/view.html" id="viewform">
<input type="hidden" name="url" id="viewUrl" value="" />
<!-- customize by adding more inputs with the viewer parameters -->
Open in the <button>OPML Viewer</button> (requires JavaScript).
</form>
</p>
<p>
<time>
<xsl:value-of select="head/dateCreated" />
Expand Down
2 changes: 1 addition & 1 deletion src/components/layout/Head.astro
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { FeedManager } from "@/features/feeds/feedManager";
rel="alternate"
type="application/rss+xml"
title={feed.name}
href={feed.rssUrl}
href={feed.urls.rss}
/>
))
}
Expand Down
12 changes: 10 additions & 2 deletions src/components/layout/sidebar/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { NavDivider } from "@/components/layout/sidebar/navDivider";
import {
faBookBookmark,
faBullhorn,
faCommentDots,
faHome,
faMagnifyingGlassChart,
faNewspaper,
Expand All @@ -24,7 +25,7 @@ export default function Sidebar({ url }: { url: URL }) {

<NavGroup label="news">
<NavLink
href="/pulse/browse/1"
href="/pulse/browse"
label="Newsfeed"
currentUrl={url}
icon={faNewspaper}
Expand Down Expand Up @@ -61,9 +62,16 @@ export default function Sidebar({ url }: { url: URL }) {

<div>
<NavGroup label="about">
<NavLink
href="https://github.com/kevin8181/scouting411/issues/new/choose"
label="Give Feedback"
newTab
currentUrl={url}
icon={faCommentDots}
/>
<NavLink
href="https://github.com/kevin8181/scouting411"
label="Github"
label="GitHub"
newTab
currentUrl={url}
icon={faGitAlt}
Expand Down
2 changes: 1 addition & 1 deletion src/components/react/post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function RenderPost({ post }: { post: Post }) {
{post.description ?? "No excerpt available."}
</span>
<span className="flex items-center gap-2 text-xs text-gray-700">
<a href={post.feed.overviewUrl} className="underline">
<a href={post.feed.urls.overview} className="underline">
{post.feed.name}
</a>

Expand Down
31 changes: 22 additions & 9 deletions src/features/feeds/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class Feed {
readonly name: string;
readonly slug: string;
readonly description: string;
readonly homepageUrl: UrlShaped;
private readonly _homepageUrl: UrlShaped;
private readonly _adapter: FeedAdapter;

// LIFECYCLE
Expand All @@ -27,7 +27,7 @@ export class Feed {
this.name = opts.name;
this.slug = opts.slug;
this.description = opts.description;
this.homepageUrl = opts.homepageUrl;
this._homepageUrl = opts.homepageUrl;
this._adapter = opts.adapter;
}

Expand All @@ -36,13 +36,26 @@ export class Feed {
get type() {
return this._adapter.type;
}
/** relative href to the detail page for this feed */
get overviewUrl() {
return `/pulse/sources/${this.slug}`;
}
/** relative href to the generated rss feed */
get rssUrl() {
return `/feeds/${this.slug}/rss`;
// /** relative href to the detail page for this feed */
// get overviewUrl() {
// return `/pulse/sources/${this.slug}`;
// }
// /** relative href to the generated rss feed */
// get rssUrl() {
// return `/feeds/${this.slug}/rss`;
// }

get urls() {
return {
/** relative href to the detail page for this feed */
overview: `/pulse/sources/${this.slug}`,
/** relative href to the generated rss feed */
rss: `/feeds/${this.slug}/rss`,
/** relative href to the generated atom feed */
atom: `/feeds/${this.slug}/atom`,
/** upstream's html homepage */
homepage: this._homepageUrl,
};
}

// INSTANCE METHODS
Expand Down
88 changes: 53 additions & 35 deletions src/features/postsQuery/filter.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,53 @@
// import { z } from "astro/zod";
// import { Post } from "@/features/posts/post";

// export function filterPosts({
// posts,
// filterOpts,
// }: {
// posts: Post[];
// filterOpts: z.infer<typeof filterOptsSchema>;
// }) {
// return posts.filter((_post) => {
// const predicates = buildPredicates(filterOpts);

// // if all of the predicates are true, return true
// if (Object.values(predicates).every((predicate) => predicate)) {
// return true;
// }

// // if any of the predicates are false, return false
// return false;
// });
// }

// /** check a post against each filter. return an object with a bool for each predicate */
// function buildPredicates(filters: FilterOpts) {
// return {

// };
// }

// export const filterOptsSchema = z.object({
// dateBefore: z.coerce.date().optional(),
// dateAfter: z.coerce.date().optional(),
// }).strict();
// export type FilterOpts = z.infer<typeof filterOptsSchema>;
import { z } from "astro/zod";
import { Post } from "@/features/posts/post";
import type { Predicate } from "@/util/utilTypes";

export function filterPosts(
posts: Post[],
opts: z.infer<typeof filterOptsSchema>,
) {
const predicates = buildPredicates(opts);

return posts.filter((post) =>
predicates.every((predicate) => predicate(post)),
);
}

/** turn a filter config into an array of predicates */
function buildPredicates(filter: FilterOpts): Predicate<Post>[] {
const predicates: Predicate<Post>[] = [];

for (const [key, value] of Object.entries(filter) as [
keyof FilterOpts,
FilterOpts[keyof FilterOpts],
][]) {
if (value !== undefined) {
const factory = predicateFactories[key];
predicates.push(factory(value as NonNullable<typeof value>));
}
}

return predicates;
}

const predicateFactories: PredicateFactories<FilterOpts, Post> = {
keyword: (value: string): Predicate<Post> => {
return (post) => {
const titleMatch = post.title.toUpperCase().includes(value.toUpperCase());
const descriptionMatch = !!post.description
?.toUpperCase()
.includes(value.toUpperCase());

return titleMatch || descriptionMatch;
};
},
//todo add filters for datebefore, dateafter
};
type PredicateFactories<F, T> = {
[K in keyof F]-?: (value: NonNullable<F[K]>) => Predicate<T>;
};

type FilterOpts = z.infer<typeof filterOptsSchema>;
export const filterOptsSchema = z.object({
keyword: z.string().optional(),
});
24 changes: 14 additions & 10 deletions src/features/postsQuery/query.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
import { FeedManager } from "@/features/feeds/feedManager";
import { z } from "astro/zod";
import { sortPosts, sortOptsSchema } from "@/features/postsQuery/sort";
import {
paginate,
paginateArray,
paginateOptsSchema,
type PaginatedResults,
} from "@/util/paginate";
} from "@/util/paginateArray";
import { filterPosts, filterOptsSchema } from "@/features/postsQuery/filter";
import { Post } from "@/features/posts/post";

export async function queryPosts(
opts: QueryOpts,
): Promise<PaginatedResults<Post>> {
// get all the posts. todo make it so you can start with only a subset of the feeds
// todo make it so you can start with only a subset of the feeds
const posts = await FeedManager.allPosts();

// todo add filtering and sorting
const filteredPosts = filterPosts(posts, opts.filter);

return paginate(posts, opts.paginate);
const sortedPosts = sortPosts(filteredPosts, opts.sort);

return paginateArray(sortedPosts, opts.paginate);
}

type QueryOpts = z.infer<typeof queryOptsSchema>;
//todo
//eslint-disable-next-line
const queryOptsSchema = z.object({
paginate: paginateOptsSchema,
export type QueryOpts = z.infer<typeof queryOptsSchema>;
export const queryOptsSchema = z.object({
filter: filterOptsSchema.default({}),
sort: sortOptsSchema.default({ mode: "date", direction: "desc" }),
paginate: paginateOptsSchema.default({ page: 1, maxPageSize: 20 }),
});
Loading
Loading