Skip to content

Commit

Permalink
Fix other code
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Apr 8, 2024
1 parent f8d2af7 commit 3260cb8
Show file tree
Hide file tree
Showing 19 changed files with 54 additions and 66 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/markdown-link-check.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"aliveStatusCodes": [0, 200, 429],
"ignorePatterns": [{ "generated": "packages/docs/src/content/docs/reference/plugins/*.md" }]
"ignorePatterns": [
{ "generated": "packages/docs/src/content/docs/reference/plugins/*.md" }
]
}
12 changes: 6 additions & 6 deletions knip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const config: KnipConfig = {
ignore: ['templates/**'],
workspaces: {
'.': {
ignoreBinaries: ['knip']
ignoreBinaries: ['knip'],
},
'packages/knip': {
entry: ['src/{index,cli}.ts!', 'src/plugins/*/index.ts!'],
Expand All @@ -14,14 +14,14 @@ const config: KnipConfig = {
ignoreDependencies: ['@pnpm/logger'],
'node-test-runner': {
entry: ['test/**/*.test.ts'],
project: ['test/**/*.ts']
}
project: ['test/**/*.ts'],
},
},
'packages/docs': {
entry: ['{remark,scripts}/*.ts', 'src/components/{Head,Header,Footer}.astro!'],
ignore: 'config.ts'
}
}
ignore: 'config.ts',
},
},
};

export default config;
2 changes: 1 addition & 1 deletion packages/docs/astro.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import starlight from '@astrojs/starlight';
import type { ExpressiveCodeTheme } from '@astrojs/starlight/expressive-code';
import { defineConfig } from 'astro/config';
import remarkDirective from 'remark-directive';
import { base } from './config.js';
import { fixInternalLinks } from './remark/fixInternalLinks.ts';
import { transformDirectives } from './remark/transformDirectives.ts';
import type { ExpressiveCodeTheme } from '@astrojs/starlight/expressive-code';

const setForeground = (theme: ExpressiveCodeTheme, scope: string, value: string) => {
const settings = theme.settings.find(setting => setting.scope?.includes(scope));
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/remark/fixInternalLinks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { bold, cyan, dim } from 'kleur/colors';
import { visit, type Visitor } from 'unist-util-visit';
import type { Node, Parent } from 'unist';
import { type Visitor, visit } from 'unist-util-visit';

interface LinkNode extends Node {
url: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/remark/transformDirectives.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { h } from 'hastscript';
import { visit, type Visitor } from 'unist-util-visit';
import type { Node, Parent } from 'unist';
import { type Visitor, visit } from 'unist-util-visit';

interface DirectiveNode extends Node {
type: 'textDirective' | 'leafDirective' | 'containerDirective';
Expand Down
12 changes: 6 additions & 6 deletions packages/docs/scripts/generate-plugin-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import fs from 'node:fs/promises';
// eslint-disable-next-line n/no-restricted-import
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import type { Root } from 'mdast';
import remarkDirective from 'remark-directive';
import remarkFrontmatter from 'remark-frontmatter';
import remarkParse from 'remark-parse';
import remarkStringify from 'remark-stringify';
import { unified } from 'unified';
import type { Node } from 'unist';
import { u } from 'unist-builder';
import { base } from '../config.js';
import type { Plugin } from '../../knip/src/types/plugins.js';
import type { Root } from 'mdast';
import type { Node } from 'unist';
import { base } from '../config.js';

const rootDir = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
const referenceDocsDir = path.join(rootDir, 'src/content/docs/reference');
Expand Down Expand Up @@ -98,7 +98,7 @@ for await (const dir of directories) {

plugins.sort((a, b) => (a[1] < b[1] ? -1 : 1));

const frontmatter = u('yaml', `title: Plugins\ntableOfContents: false`);
const frontmatter = u('yaml', 'title: Plugins\ntableOfContents: false');

const tree = u('root', [
frontmatter,
Expand All @@ -108,7 +108,7 @@ const tree = u('root', [
{ spread: false, ordered: false },
plugins.map(plugin =>
u('listItem', [
u('link', { title: plugin[0], url: (base === '/' ? '' : base) + `/reference/plugins/${plugin[1]}` }, [
u('link', { title: plugin[0], url: `${base === '/' ? '' : base}/reference/plugins/${plugin[1]}` }, [
u('text', plugin[0]),
]),
])
Expand All @@ -118,5 +118,5 @@ const tree = u('root', [
]),
]);

console.log(`Writing plugin list to plugins.md`);
console.log('Writing plugin list to plugins.md');
await writeTree(tree, path.join(referenceDocsDir, 'plugins.md'));
5 changes: 1 addition & 4 deletions packages/docs/src/components/Contributors.astro
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ interface Contributor {
login: string;
}
const url = new URL(
`/repos/webpro/knip/contributors`,
'https://api.github.com'
);
const url = new URL('/repos/webpro/knip/contributors', 'https://api.github.com');
url.searchParams.set('per_page', '100');
const contributors: Contributor[] = isFetch
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/src/components/Footer.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
import type { Props } from '@astrojs/starlight/props';
import Default from '@astrojs/starlight/components/Footer.astro';
import type { Props } from '@astrojs/starlight/props';
import SimpleAnalytics from './SimpleAnalytics.html';
---

Expand Down
4 changes: 2 additions & 2 deletions packages/docs/src/components/Head.astro
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
import type { Props } from '@astrojs/starlight/props';
import Default from '@astrojs/starlight/components/Head.astro';
import type { Props } from '@astrojs/starlight/props';
const slug = Astro.props.slug;
const url = new URL(Astro.url);
url.pathname = `/og/docs${slug ? '/' + slug : ''}.webp`;
url.pathname = `/og/docs${slug ? `/${slug}` : ''}.webp`;
url.searchParams.append('v', '2');
---

Expand Down
10 changes: 4 additions & 6 deletions packages/docs/src/components/Header.astro
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
---
import type { Props } from '@astrojs/starlight/props';
import SiteTitle from '@astrojs/starlight/components/SiteTitle.astro';
import Search from '@astrojs/starlight/components/Search.astro';
import Select from '@astrojs/starlight/components/Select.astro';
import SiteTitle from '@astrojs/starlight/components/SiteTitle.astro';
import SocialIcons from '@astrojs/starlight/components/SocialIcons.astro';
import ThemeSelect from '@astrojs/starlight/components/ThemeSelect.astro';
import Select from '@astrojs/starlight/components/Select.astro';
import type { Props } from '@astrojs/starlight/props';
import { defaultVersion, versions } from '../../config.js';
const url = new URL(Astro.url);
const currentVersion = /^\/v\d+/.test(url.pathname)
? url.pathname.split('/')[1]
: defaultVersion;
const currentVersion = /^\/v\d+/.test(url.pathname) ? url.pathname.split('/')[1] : defaultVersion;
const options = versions.map(([version, label]) => ({
label,
selected: currentVersion === version,
Expand Down
6 changes: 1 addition & 5 deletions packages/docs/src/components/Tweet.astro
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
---
import sprites from '../assets/sprites.svg';
import {
replaceShortenedUrls,
type TweetWithUser,
formatTimestamp,
} from '../util/tweet.js';
import { type TweetWithUser, formatTimestamp, replaceShortenedUrls } from '../util/tweet.js';
const tweet: TweetWithUser = replaceShortenedUrls(Astro.props.data);
---
Expand Down
28 changes: 7 additions & 21 deletions packages/docs/src/components/Tweets.astro
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
import { readFile } from 'node:fs/promises';
import Tweet from './Tweet.astro';
import { Card, CardGrid } from '@astrojs/starlight/components';
import { type TweetsResponse, formatTimestamp } from '../util/tweet.js';
import Tweet from './Tweet.astro';
const BEARER_TOKEN = import.meta.env.BEARER_TOKEN;
Expand All @@ -28,24 +28,12 @@ const tweetIds = [
'1692942539614028086',
];
const tweet_url = new URL(`/2/tweets`, 'https://api.twitter.com');
const tweet_url = new URL('/2/tweets', 'https://api.twitter.com');
tweet_url.searchParams.set('ids', tweetIds.join(','));
tweet_url.searchParams.set(
'expansions',
['author_id', 'attachments.media_keys'].join(',')
);
tweet_url.searchParams.set(
'user.fields',
['name', 'username', 'profile_image_url'].join(',')
);
tweet_url.searchParams.set(
'tweet.fields',
['note_tweet', 'created_at', 'public_metrics', 'entities'].join(',')
);
tweet_url.searchParams.set(
'media.fields',
['type', 'preview_image_url', 'url', 'alt_text', 'variants'].join(',')
);
tweet_url.searchParams.set('expansions', ['author_id', 'attachments.media_keys'].join(','));
tweet_url.searchParams.set('user.fields', ['name', 'username', 'profile_image_url'].join(','));
tweet_url.searchParams.set('tweet.fields', ['note_tweet', 'created_at', 'public_metrics', 'entities'].join(','));
tweet_url.searchParams.set('media.fields', ['type', 'preview_image_url', 'url', 'alt_text', 'variants'].join(','));
const tweets: TweetsResponse = isFetch
? await fetch(tweet_url.href, {
Expand All @@ -64,9 +52,7 @@ interface Testimonial {
url: string;
}
const testimonials: Testimonial[] = JSON.parse(
await readFile('mock/testimonials.json', 'utf-8')
);
const testimonials: Testimonial[] = JSON.parse(await readFile('mock/testimonials.json', 'utf-8'));
---

<style>
Expand Down
3 changes: 1 addition & 2 deletions packages/docs/src/content/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { docsSchema, i18nSchema } from '@astrojs/starlight/schema';
// eslint-disable-next-line import/no-unresolved
import { defineCollection } from 'astro:content';
import { docsSchema, i18nSchema } from '@astrojs/starlight/schema';

export const collections = {
docs: defineCollection({ schema: docsSchema() }),
Expand Down
6 changes: 3 additions & 3 deletions packages/docs/src/pages/og/[...route].ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function breakText(str: string, maxLines: number, maxLineLen: number) {
const segmenterTitle = new Intl.Segmenter('en-US', { granularity: 'word' });
const segments = segmenterTitle.segment(str);

let linesOut = [''];
const linesOut = [''];
let lineNo = 0;
let offsetInLine = 0;
for (const word of Array.from(segments)) {
Expand Down Expand Up @@ -58,7 +58,7 @@ const S = ({ title }: { title: string; description: string[] }) => {
return template.replace('<!-- titleText -->', titleText);
};

export const GET = async function ({ params }: { params: { route: string } }) {
export const GET = async ({ params }: { params: { route: string } }) => {
const pages = await getPages();
const pageEntry = pages[params.route];
if (!pageEntry) return new Response('Page not found', { status: 404 });
Expand All @@ -81,7 +81,7 @@ export const GET = async function ({ params }: { params: { route: string } }) {
});
};

export const getStaticPaths = async function () {
export const getStaticPaths = async () => {
const pages = await getPages();
return Object.keys(pages).map(route => ({ params: { route } }));
};
4 changes: 2 additions & 2 deletions packages/docs/src/util/tweet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export const replaceShortenedUrls = (tweet: TweetWithUser) => {
let text = (tweet.note_tweet?.text ?? tweet.text).replace(/^(@[^ ]+ )*/, '');
if (!tweet.entities.urls) return { ...tweet, text };
tweet.entities.urls.sort((a, b) => b.start - a.start);
tweet.entities.urls.forEach(urlEntity => {
for (const urlEntity of tweet.entities.urls) {
if (urlEntity.media_key) {
const media = (tweet.media ?? []).find(media => media.media_key === urlEntity.media_key);
if (media && media.type === 'photo') {
Expand All @@ -13,7 +13,7 @@ export const replaceShortenedUrls = (tweet: TweetWithUser) => {
} else {
text = text.replace(urlEntity.url, `<a href="${urlEntity.expanded_url}">${urlEntity.expanded_url}</a>`);
}
});
}
if (tweet.media && tweet.note_tweet?.text) {
text = text + tweet.media.map(media => `<img src="${media.url}" alt="${media.alt_text}" />`).join('');
}
Expand Down
8 changes: 7 additions & 1 deletion packages/knip/.release-it.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{
"hooks": {
"before:init": ["npm run lint", "npm run build", "npm run knip", "npm run knip:production", "npm test"],
"before:init": [
"npm run lint",
"npm run build",
"npm run knip",
"npm run knip:production",
"npm test"
],
"after:bump": ["git add ../../package-lock.json"]
},
"github": {
Expand Down
2 changes: 1 addition & 1 deletion packages/knip/fixtures/compilers/knip.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import '@mdx-js/mdx';

module.exports = {
export default {
compilers: {
md: (text, path) => {
if (!path) throw new Error('Path not passed to compiler');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'webpack';
require('webpack');

const config = [
{
Expand Down
6 changes: 5 additions & 1 deletion packages/knip/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,9 @@
},
"include": ["./src/**/*.ts"],
"exclude": [],
"files": ["./@types/github-codeowners/index.d.ts", "./@types/summary/index.d.ts", "./@types/bash-parser/index.d.ts"]
"files": [
"./@types/github-codeowners/index.d.ts",
"./@types/summary/index.d.ts",
"./@types/bash-parser/index.d.ts"
]
}

0 comments on commit 3260cb8

Please sign in to comment.