Hello,
I posted a follow-up question under another similar one but not solved. My goal is to make all job details page working without showing 404 and a bunch of md files in my content folders. So I start a new topic here:
Currently, I have /content/careers/default.md with below content:
...
type: "careers"
title: "171"
...
All jobs are listed in /layouts/careers/list.html via a successgul API get call:
…
<div>
{{ $allJobs := getJSON "MY_JOB_API" }}
<ul>
<li>{{ job_170}}</li>
<li>{{ job_171}}></li>
</ul>
</div>
…
Normal HTML in /layouts/careers/single.html:
<!DOCTYPE html>
<html lang="en-US">
blahblah.........
Current Performance:
When users click on job 171 on “XZY.com/careers/”, they will be directed to “XYZ.com/careers/171” and this is good because I have title: “171” in my markdown file. However, when users click on another job like 170, they will be directed to “XYZ.com/careers/170” which is correct but it shows 404 instead because I don’t have a markdown file with title: “170” inside.
Expectation:
Not having a bunch of md files for each job in content/careers folder, users should be directed to “XYZ.com/careers/clicked_ID” rather than 404 no matter which job they click on “XYZ.com/careers/”.
What I did:
Option 1 – dynamic title in front matter file:
In /content/careers/default.md
:
...
type: "careers"
title: "{{ $jobID }}"
...
{{ $allJobs := getJSON "MY_URL_TO_GET_ALL_JOBS_WITH_IDS" }}
{{ range $allJobs.data }}
{{ $jobID := .id }}
Or
...
type: "careers"
title: "[1, 2, 3, ..., 20]" (some sort of array of all job ids)
...
Option 2 – workaround with shortcode and not having permalinks in config:
In config.toml
:
.......(other code)......
(no specified permalinks for careers)
.......(other code)......
In /content/careers/default.md
:
...
type: "careers"
...
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8>
etc..
I’ve been searched for LOTS of Hugo articles, blogs, and discussions but no luck. I really appreciate your help!
Jen