Remove axios and commit backend changes to sitemap

This commit is contained in:
Julien Nahum 2024-01-02 19:03:14 +01:00
parent 55debc539c
commit 6900fd572f
4 changed files with 16 additions and 54 deletions

View File

@ -9,62 +9,24 @@ use App\Models\Template;
class SitemapController extends Controller
{
/**
* Contains route name and the associated priority
*
* @var array
*/
protected $urls = [
['/', 1],
['/pricing', 0.9],
['/privacy-policy', 0.5],
['/terms-conditions', 0.5],
['/login', 0.4],
['/register', 0.4],
['/password/reset', 0.3],
['/form-templates', 0.9],
public function index(Request $request)
{
return [
...$this->getTemplatesUrls()
];
public function getSitemap(Request $request)
{
$sitemap = Sitemap::create();
foreach ($this->urls as $url) {
$sitemap->add($this->createUrl($url[0], $url[1]));
}
$this->addTemplatesUrls($sitemap);
$this->addTemplatesTypesUrls($sitemap);
$this->addTemplatesIndustriesUrls($sitemap);
return $sitemap->toResponse($request);
}
private function createUrl($url, $priority, $frequency = 'daily')
private function getTemplatesUrls()
{
return Url::create($url)->setPriority($priority)->setChangeFrequency($frequency);
}
private function addTemplatesUrls(Sitemap $sitemap)
{
Template::where('publicly_listed', true)->chunk(100, function ($templates) use ($sitemap) {
$urls = [];
Template::where('publicly_listed', true)->chunk(100, function ($templates) use (&$urls) {
foreach ($templates as $template) {
$sitemap->add($this->createUrl('/form-templates/' . $template->slug, 0.8));
$urls[] = [
'loc' => '/templates/' . $template->slug
];
}
});
}
private function addTemplatesTypesUrls(Sitemap $sitemap)
{
$types = json_decode(file_get_contents(resource_path('data/forms/templates/types.json')), true);
foreach ($types as $type) {
$sitemap->add($this->createUrl('/form-templates/types/' . $type['slug'], 0.7));
}
}
private function addTemplatesIndustriesUrls(Sitemap $sitemap)
{
$industries = json_decode(file_get_contents(resource_path('data/forms/templates/industries.json')), true);
foreach ($industries as $industry) {
$sitemap->add($this->createUrl('/form-templates/industries/' . $industry['slug'], 0.7));
}
return $urls;
}
}

View File

@ -1,5 +1,4 @@
import {defineStore} from 'pinia'
import axios from 'axios'
export const useAuthStore = defineStore('auth', {
state: () => {
@ -88,8 +87,8 @@ export const useAuthStore = defineStore('auth', {
},
async fetchOauthUrl(provider) {
const {data} = await axios.post(`/api/oauth/${provider}`)
return data.url
// const {data} = await axios.post(`/api/oauth/${provider}`)
// return data.url
}
}
})

View File

@ -167,6 +167,8 @@ Route::prefix('content')->name('content.')->group(function () {
Route::get('changelog/entries', [\App\Http\Controllers\Content\ChangelogController::class, 'index'])->name('changelog.entries');
});
Route::get('/sitemap-urls', [\App\Http\Controllers\SitemapController::class, 'index'])->name('sitemap.index');
// Templates
Route::prefix('templates')->group(function () {
Route::get('/', [TemplateController::class, 'index'])->name('templates.index');

View File

@ -28,6 +28,7 @@ Route::post(
'/upload-file',
[\App\Http\Controllers\Content\FileUploadController::class, 'upload']
)->middleware([]);
Route::get('local/temp/{path}', function (Request $request, string $path){
if (!$request->hasValidSignature()) {
abort(401);
@ -37,7 +38,5 @@ Route::get('local/temp/{path}', function (Request $request, string $path){
return $response;
})->where('path', '(.*)')->name('local.temp');
Route::get('/sitemap.xml', [\App\Http\Controllers\SitemapController::class, 'getSitemap'])->name('sitemap');
Route::get('caddy/ask-certificate/{secret?}', [\App\Http\Controllers\CaddyController::class, 'ask'])
->name('caddy.ask')->middleware(\App\Http\Middleware\CaddyRequestMiddleware::class);