From 1a9c4f9bc0d4ab4ed871424d1c8e18ba5cbe28da Mon Sep 17 00:00:00 2001
From: Federico <me@fregante.com>
Date: Fri, 4 Jun 2021 23:39:17 +0700
Subject: `embed-gist-inline` improve gist detection

---
 source/features/embed-gist-inline.tsx | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

(limited to 'source/features/embed-gist-inline.tsx')

diff --git a/source/features/embed-gist-inline.tsx b/source/features/embed-gist-inline.tsx
index efb096f5..b7dc4dd5 100644
--- a/source/features/embed-gist-inline.tsx
+++ b/source/features/embed-gist-inline.tsx
@@ -6,7 +6,7 @@ import * as pageDetect from 'github-url-detection';
 import features from '.';
 import {getCleanPathname} from '../github-helpers';
 
-function parseGistLink(link: HTMLAnchorElement): string | void {
+function parseGistLink(link: HTMLAnchorElement): string | undefined {
 	if (link.host === 'gist.github.com') {
 		return getCleanPathname(link);
 	}
@@ -14,15 +14,12 @@ function parseGistLink(link: HTMLAnchorElement): string | void {
 	if (link.host === location.host && link.pathname.startsWith('gist/')) {
 		return link.pathname.replace('/gist', '').replace(/\/$/, '');
 	}
+
+	return undefined;
 }
 
 function isGist(link: HTMLAnchorElement): boolean {
-	const gistUrl = parseGistLink(link);
-	return Boolean(
-		gistUrl &&
-		!gistUrl.includes('.') && // Exclude links to embed files
-		gistUrl.includes('/', 1) // Exclude user links
-	);
+	return parseGistLink(link)?.replace(/[^/]/g, '').length === 1; // Exclude user links and file links
 }
 
 const isOnlyChild = (link: HTMLAnchorElement): boolean => link.textContent!.trim() === link.parentNode!.textContent!.trim();
-- 
cgit v1.2.3

