Skip to content

Commit d03276e

Browse files
committed
importer update
1 parent 4ad9330 commit d03276e

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

app/src/Commands/FeedImporter.php

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -134,22 +134,34 @@ public function import(string $csvPath): void
134134
private function importFeed(string $url, string $name, string $tags, string $category): array
135135
{
136136
try {
137-
// 1. Discover feed URL
138-
$feedUrl = $this->discoverFeedUrl($url);
139-
if (!$feedUrl) {
140-
return [
141-
'status' => 'error',
142-
'message' => 'Could not discover feed URL'
143-
];
144-
}
137+
// 1. Detect platform and set feed URL and type
138+
$isSubstack = stripos($url, 'substack.com') !== false;
139+
$isButtondown = stripos($url, 'buttondown') !== false;
140+
141+
if ($isSubstack) {
142+
$feedUrl = rtrim($url, '/') . '/feed';
143+
$feedType = 'rss2';
144+
} elseif ($isButtondown) {
145+
$feedUrl = rtrim($url, '/') . '/rss';
146+
$feedType = 'rss2';
147+
} else {
148+
// Discover feed URL for other platforms
149+
$feedUrl = $this->discoverFeedUrl($url);
150+
if (!$feedUrl) {
151+
return [
152+
'status' => 'error',
153+
'message' => 'Could not discover feed URL'
154+
];
155+
}
145156

146-
// 2. Detect feed type
147-
$feedType = $this->feedDetector->detectType($feedUrl);
148-
if (!$feedType) {
149-
return [
150-
'status' => 'error',
151-
'message' => 'Could not detect feed type'
152-
];
157+
// Detect feed type
158+
$feedType = $this->feedDetector->detectType($feedUrl);
159+
if (!$feedType) {
160+
return [
161+
'status' => 'error',
162+
'message' => 'Could not detect feed type'
163+
];
164+
}
153165
}
154166

155167
// 3. Check if feed already exists
@@ -207,18 +219,6 @@ private function importFeed(string $url, string $name, string $tags, string $cat
207219
private function discoverFeedUrl(string $url): ?string
208220
{
209221
try {
210-
$url = trim($url);
211-
212-
// Handle Substack URLs
213-
if (stripos($url, 'substack.com') !== false) {
214-
return rtrim($url, '/') . '/feed';
215-
}
216-
217-
// Handle Buttondown URLs
218-
if (stripos($url, 'buttondown') !== false) {
219-
return rtrim($url, '/') . '/rss';
220-
}
221-
222222
// First, try the URL directly
223223
$feedType = $this->feedDetector->detectType($url);
224224
if ($feedType) {

0 commit comments

Comments
 (0)