Hugo - MD file in main menu gives 404 - hugo

I have a hugo site with an about page inside the repo_name/themes/theme_name/content/file.md
In my config.toml file I added the lines.
[[menu.main]]
identifier = "about"
name = "about"
url = "/about/"
weight = 2
But when I hit the URL localhost:1313/about/ its giving 404.

Your about.md file can be seen as a resource instead of a page. Adding an _index.md file to your content folder (the home page) will fix this. Additionally I would think that the about page is not part of the theme, but part of your repo. Not sure if this causes the 404, but I think the page belongs here:
/repo_name/content/about.md

Related

Is there a way to rename automatically generated routes JSON file in Next.js?

I have a problem, when I click to go to the /analytics page on my site, adblockers block the analytics.json file that's being requested by Next.js as they think it's an analytics tracker (it's not, it's a page listing analytics products).
Is there a way to rename the route files Next.js uses when navigating to server-side rendered pages on the client-side?
I want to either obfuscate the names so they're not machine readable, or have a way to rename them all.
Any help appreciated.
With thanks to #gaston-flores I've managed to get something working.
In my instance /analytics is a dynamic page for a category, so I moved my pages/[category]/index.tsx file to pages/[category]/category.tsx and added the following rewrite:
// next.config.js
module.exports = {
async rewrites() {
return [
{
source: "/:category",
destination: "/:category/category",
},
];
},
};
This now gets the category.json file rather than analytics.json, which passes the adblockers checks and renders as expected.
Note that due to having a dynamic file name in the pages/[category] directory (pages/[category]/[product].tsx), I had to move that to pages/[category]/product/[product].tsx as I was seeing the /analytics page redirected to /analytics/category for some reason without this tweak.

hugo URLs with protocol (http) not supported

I am using hugo (https://gohugo.io/) and trying to make an external link in the menu (docsy theme).
I changed the _index.md to:
---
title: "Documentation"
linkTitle: "Documentation"
url: "https://www.myurl.com"
weight: 20
menu:
main:
weight: 20
---
However hugo reports:
Rebuild failed: URLs with protocol (http*) not supported
Could anyone advise of how to create an external URL link directly on the menu?
Thanks, Gregor
Keep in mind that "url" is a predefined front matter variable that is meant to be used for defining the full path to the content page from the site root. If you want to add an external link in your front matter, I'd recommend giving the variable a different name, e.g. "external_url".
I just added something like this:
[[menu.main]]
name = "GitHub"
weight = 50
url = "https://github.com/google/docsy/"
To the config.toml file.
I found this solution for the docsy theme here: https://www.docsy.dev/docs/adding-content/navigation/
Hope this helps, Gregor

Change where a Page is displayed in the URL

I have setup my website whereby the main parental/tree structure is Home > Shop > Category > Product" with > denoting parent of.
This works fine, however when accessing a Product(Page) the url is automatically (and correctly) configured at /shop/test-category/test-product by Wagtail.
I would like to change it so that the product is actually displayed as being at the root level (even though it isn't). So if a user accesses Test Product it would be at /test-product/.
Looking through the docs, the RoutablePageMixin seems like it might do the trick but I have no idea how to go about implementing it. Any ideas?
This solution will make the product available at both URLS:
/shop/test-category/test-product/
/test-product/
Approach:
You are correct that you will need to use RoutablePageMixin, be sure to install it in your installed_apps as per the instructions before importing.
The example below adds RoutablePageMixin to your HomePage, as this is the page that will be located at the root / URL. We do a regex check and match for a single slug before a trailing /.
Then we see if we can find a ProductPage with that slug, and serve (or redirect) to that page. Finally, if there is no match, we call the home_page's serve method with the current request to handle anything else. This may be an incorrect URL or a correct sub-page URL.
Caveats:
If you have a sub-page at the same slug as a product page, the sub-page will never load, there are no smarts in this code to work around that. You could put some logic in the validation of product names and sub-page names if this becomes an issue in the future.
This does not consider SEO issues, search engines will treat these as different pages and hence you may want to think about declaring your canonical URL in your meta tags.
This does not redirect back from /shop/test-category/test-product/ to /test-product/ - that can be done by overriding the serve method on your ProductPage and redirecting to something like home_page.url + '/' + self.slug.
Example Code:
# models.py - assuming all your models are in one file
from django.db import models
from django.shortcuts import redirect # only needed if redirecting
from wagtail.admin.edit_handlers import FieldPanel
from wagtail.contrib.wagtailroutablepage.models import RoutablePageMixin, route
from wagtail.core.models import Page
class ProductPage(Page):
price = models.DecimalField(max_digits=5, decimal_places=2)
content_panels = Page.content_panels + [
FieldPanel('price')
]
class HomePage(RoutablePageMixin, Page):
#route(r'^(?P<product_slug>[\w-]+)/$')
def default_view(self, request, product_slug=None):
"""Route will match any `my-product-slug/` after homepage route."""
product_page = Page.objects.exact_type(ProductPage).filter(slug=product_slug).first()
if product_page:
# option 1 - redirect to the product's normal URL (non-permanent redirect)
# return redirect(product_page.specific.url)
# option 2 - render the product page at this URL (no redirect)
return product_page.specific.serve(request)
else:
# process to normal handling of request so correct sub-pages work
return self.serve(request)

Laravel returning a 404 on an image

This should be fairly simple though it is completely stumping me.
I have a backend Laravel installation running on localhost:8000
I have a front end Angular app running on localhost:9001.
I have some 'static' images I have included in my seed data (eg.
'1', 'user.png'), these images are being rendered perfectly in my front end (they are also served from the exact place my image uploads are going).
The URL I am currently serving images from is http://localhost:8000/images/{filename}
I can upload images from the front to the back end and they appear in the DB and the image is being put in the filesystem, I'm populating the correct URL in my front end (as evidenced by the previous URL).
My uploaded images are not being shown.
In my logs I am getting:
[2015-01-20 18:13:49] local.ERROR: NotFoundHttpException Route: http://localhost:8000/images/j249ae747ce28c317e02f1fb6d0a10c3.jpg [] []
[2015-01-20 18:13:49] local.ERROR: exception 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException'
I tried a method in my routes file, but couldnt see why, when I am already serving some images already?
I have also set all permissions to 755 on my /images folder.
Any ideas?
I'm not sure I follow every bit of multi-system interaction you have going on, but I'd drop back to first HTTP principles.
Try accessing the image URL directly.
http://localhost:8000/images/j249ae747ce28c317e02f1fb6d0a10c3.jpg
If the error in your browser (or your logs, if you're not developing with debug set to true) is
local.ERROR: NotFoundHttpException Route: http://localhost:8000/images/j249ae747ce28c317e02f1fb6d0a10c3.jpg
This means your web server couldn't find a file at images/j249ae747ce28c317e02f1fb6d0a10c3.jpg, and handed the request to Laravel. This means you need to figure out why your webserver can't see the file.
Assuming you're serving index.php from the public folder
Do you have a public/images/j249ae747ce28c317e02f1fb6d0a10c3.jpg file?
Are you sure? Copy and paste the path into terminal and to a ls public/images/j249ae747ce28c317e02f1fb6d0a10c3.jpg to make sure your brain isn't missing some subtle case issue
Are any errors showing up in your web server's logs (not Laravel's)
Can you create a text/html file in the images folder and serve it? If not, then you may not be pointing your web server at the folder you think you are.
Something like
http://localhost:8000/images/test.txt
http://localhost:8000/images/test.html
Some first principles debugging like that should point you in the right direction.
rm public/storage
php artisan optimize:clear
php artisan storage:link
This worked for me.
The problem is you haven't generated a url for your uploaded image
Try accessing your url like this
http://localhost:8000/storage/images/j249ae747ce28c317e02f1fb6d0a10c3.jpg
To generate the above url
Add this method \Storage::disk('public')->url(); method in your controller.This method accesses the public disk array which is found in Config\filesystems.php and it generates a url in the following format
http://localhost:8000/storage/images/j249ae747ce28c317e02f1fb6d0a10c3.jpg
For example the method below stores the image in the image folder and generates the url of the image path.
public function uploadImage(Request $request)
{
$request->validate(['image'=>'file|image|max:5000']);
$imageProfile = new ImageProfile();
if($request->hasFile('image') && $request->file('image')->isValid())
{
$image = $request->file('image')->store('images');
$imageProfile->image_profile_url = \Storage::disk('public')->url($image);
$imageProfile->save()
}
return response()->json($imageProfile,200);
}
The code returns a Json response below
{
"id": 13,
"image_profile_url ": "http://127.0.0.1:8000/storage/images/cxlogqdI8aodERsmw74nmEx7BkxkWrnyJLMH7sFj.jpeg",
"updated_at": "2020-01-13 16:27:37",
"created_at": "2020-01-13 16:27:37",
}
Try to copy the url and test it in postman.
Visit the link to learn more about Laravel file storage
Laravel File Storage
Hope it helps.
laravel 8
Controler function
public function store(Request $request)
{
$this->validate($request, [
'site_title' => 'required',
'logo_image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
]);
$input['logo_image'] = time().'.'.$request->logo_image->getClientOriginalExtension();
$request->logo_image->move(public_path('images'), $input['logo_image']);
$input['site_title'] = $request->site_title;
//dd($input);
Site_settings::create($input);
return back()->with('success','Image Uploaded successfully.');
}
blade view
<td>
<img src="{{ url('/images/').'/'.$site_settings->logo_image ?? '' }}" alt="" width="250px" height="auto">
</td>

OSClass 404 error for location search

I installed OSClass and added some ads with specific locations (eg New York). I can see that against the location, there is a count of 1 indicating that there is one ad for that location, but when I click on the name of the region (New York) to access the add, a 404 Error page comes up that the page is not found. I am a new OSClass User, so please is there something I am missing? Shouldn't the hyperlink from the Region go directly to a list of ads posted in that region without error?
Any help is greatly appreciated.
Mike
Search result page, if there aren't results, return status code 404 (Not found), you can recalculate the location item stats via oc-admin -> tools -> Location stats
open:
/oc-includes/osclass/controller/search.php
Search for:
if( count($aItems) === 0 ) {
Replace with:
if( count($aItems) === -1 ) {
Source(or for more information):
http://forums.osclass.org/3-1-x/3-1-1-search-bug-404-page-not-found/
Some times problem occurs while you install osclass in subdirectory that its name contain space.
Ex:
C:/xampp/htdocs/Free Advertisement Scripts/OsClass/
you must change it to:
/Free_Advertisement_Scripts/
I had the same issue, and it can be solved:
go to admin >Settings >Permalinks
For Page URL use p/{PAGE_SLUG}
For Category URL use {CATEGORIES}
"Fix to this is using something that make the url different, for
example cat/{CATEGORIES} or page/{PAGE_SLUG} or {PAGE_SLUG}-{PAGE_ID}
,...."
The magic, not only can I all the categories URL without pre-path,
opening the locations also work now.
src: https://github.com/osclass/Osclass/issues/907

Resources