diff --git a/app/Article.php b/app/Article.php index 296b755..1bf6314 100644 --- a/app/Article.php +++ b/app/Article.php @@ -32,6 +32,17 @@ class Article extends Model */ protected $guarded = []; + + /** + * The attributes that should be cast. + * + * @var array + */ + protected $casts = [ + 'body' => 'array', + 'meta' => 'array' + ]; + public function source() { return $this->belongsTo(Source::class); diff --git a/app/Console/Commands/ScrapeMihaaruCommand.php b/app/Console/Commands/ScrapeMihaaruCommand.php index c38953b..6f897d3 100644 --- a/app/Console/Commands/ScrapeMihaaruCommand.php +++ b/app/Console/Commands/ScrapeMihaaruCommand.php @@ -55,6 +55,9 @@ class ScrapeMihaaruCommand extends Command "body" => $article["content"], "guid" => $article["guid"], "published_date" => $article["date"], + "meta" => [ + "title" => $article["og_title"] + ] ]); diff --git a/app/Http/Controllers/SourcesController.php b/app/Http/Controllers/SourcesController.php index b4a1882..ed616ff 100644 --- a/app/Http/Controllers/SourcesController.php +++ b/app/Http/Controllers/SourcesController.php @@ -6,6 +6,7 @@ use App\Http\Resources\SourceResource; use Illuminate\Http\Request; use App\Source; use Illuminate\Http\JsonResponse; +use App\Http\Resources\ArticleResource; class SourcesController extends Controller { @@ -28,7 +29,7 @@ class SourcesController extends Controller { return response()->json([ 'source' => new SourceResource($source), - 'articles' => $source->articles()->paginate(8) + 'articles' => ArticleResource::collection($source->articles()->paginate(8)) ]); } } diff --git a/app/Http/Resources/ArticleResource.php b/app/Http/Resources/ArticleResource.php index a93b9d5..4ed2bd0 100644 --- a/app/Http/Resources/ArticleResource.php +++ b/app/Http/Resources/ArticleResource.php @@ -21,6 +21,7 @@ class ArticleResource extends JsonResource "id" => $this->id, "title" => $this->title, "author" => $this->author, + "meta" => $this->meta, "featured_image" => $this->featured_image, "url" => $this->url, "body" => $this->body, @@ -28,8 +29,8 @@ class ArticleResource extends JsonResource "source" => new SourceResource($this->source), "topics" => TopicResource::collection($this->topics), "link" => url(route('article.show',$this->id)), - "published_date" => $this->published_date, - "meta" => $this->meta + "published_date" => $this->published_date + ]; } } diff --git a/app/Services/Scrapers/MihaaruScraper.php b/app/Services/Scrapers/MihaaruScraper.php index e9626cf..72554d6 100644 --- a/app/Services/Scrapers/MihaaruScraper.php +++ b/app/Services/Scrapers/MihaaruScraper.php @@ -43,11 +43,8 @@ class MihaaruScraper $this->author = $cleaneddata; }); - $crawler->filter('article')->each(function ($node) { - $content = $node->text(); - - $input = str_replace("\n", '', $content); - $this->content = $input; + $crawler->filter('article p')->each(function ($node) { + $this->content[] = preg_replace("/[a-zA-Z]/","",$node->text()); }); $crawler->filter('.article-tags')->each(function ($node) { diff --git a/routes/web.php b/routes/web.php index 4926265..c99207e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -13,6 +13,6 @@ use Illuminate\Support\Facades\Route; | */ -Route::get('/{any?}', function () { +Route::get('{path}', function () { return view('app'); -}); \ No newline at end of file +})->where('path', '(.*)'); \ No newline at end of file