Generate Pages from Database (for large inventory)

First off let me profess my profound gratituide and appreciation for hugo. I’m not a web developer but my experience using hugo has been flawless. I’m just at the point where I can’t find good documentation for what I’m trying to do.

Second, I know my question will probably have a simple answer, I offer my apologies for my lack of brevity in contextualizing my issue

My use case for hugo is to make an ecommerce website. This hugo site is to replace or supplement an existing webstore, which is my employer.

Most themes I’ve explored and many of the examples for how to manage content with hugo centers around having markdown files somewhere in a subdirectory of /content which are rendered using partials. This part is not mysterious to me and is well documented.

The existing e-commerce website uses a database, probably sql, which I have exported as a CSV and converte to JSON for convenience. I have seen and followed the examples in data templates and was quite impressed actually. I was able to generate a list of ll the products and get images to load from their links on the existing site.

That was the extent of my progress. I was considering how to manually rework the categories, which have no straightforward way to work with hugo in their existing format (and I must really praise the multilevel menu feature of the crab theme which I discovered just yesterday!); but I’ve come up against a more vexxing issue, the one which brought me here, which I will state now:

We have over 5000 products listed on our ecommerce website. Is there a way to avoid having to have a markdown file for each and every product? All of the data for every product is in /data/data.json and it seems utterly redundant to have to have it as separate files in separate directories depending on the category, and seeing as how some categories are subcategories and the same product would need to appear in each, it just doesn’t make sense to use that sort of blog-type format.

What I really want (need) is for the product to have it’s own page with its own url which is, for example:

myecommercesite.com/partnumber

with partnumber being our internal part numbering scheme, and when substituiting the real part number it should show the product listing for that specific product.

I have looked very carefully and I can’t say that I have seen a way to have a link to a page without an accompanying markdown file / directory. Perhaps I’ve overlooked something. Surely there must be a way to do this! If there isn’t, there should be, and I will request this feature via the issues section of github.

additional context-

Hugo Static Site Generator v0.74.3/extended linux/amd64 BuildDate: unknown

I’m running this on arch linux.

A snippet of data.json - this is the database format used by networkolutions, the hosting / ecommerce provider for the existing site.

  {
    "ProductID": 107054,
    "Name": "Copper Washer 11mm X 5.5mm",
    "ShortDescription": "",
    "LongDescription": "<span style=\"font-size: large;\">Copper Washer <br />11mm OD<br />5.5mm ID<br />1.3mm Thick<br /></span>",
    "PartNumber": "9Z16XX",
    "QuantityInStock": 18554,
    "UnlimitedStock": "False",
    "ReorderLevel": "",
    "LicenseOption": "False",
    "DownloadLimit": 0,
    "Instructions": "",
    "LicenseKeys": "",
    "StoreCost": 0,
    "CustomerPrice": 0.05,
    "MSRP": 0,
    "HandlingCost": 0,
    "MinimumOrderQuantity": 1,
    "MaximumOrderQuantity": 0,
    "WeightMajor": 0,
    "WeightMinor": 0.03,
    "Length": 0,
    "Width": 0,
    "Height": 0,
    "ManufacturerPartNumber": "",
    "ManufacturerName": "",
    "Categories": "Deals;Electromechanical ~ Hardware",
    "Warehouse": "",
    "ShippingMessage": "",
    "CategorySpecial": "False",
    "HomepageSpecial": "False",
    "ShippingOption": "S",
    "TaxFree": "False",
    "ProductType": "S",
    "RelatedProducts": "",
    "PageLayout": "",
    "ProductUrl": "http://WWW.MYECOMMERCESITE.COM/9Z16XX.aspx",
    "ImageAltText": "",
    "ImageCaptionText": "",
    "ThumbnailPath": "http://www.myecommercesite.com/images/products/thumb/9z16XX.png",
    "MediumImagePath": "http://www.myecommercesite.com/images/products/display/9z16XX.png",
    "LargeImagePath": "http://www.myecommercesite.com/images/products/detail/9z16XX.png",
    "MetaTitle": "Copper Washer 11mm X 5.5mm",
    "MetaDescription": "",
    "MetaKeywords": "",
    "SortOrder": 0,
    "Enable": "True",
    "Purchasable": "True",
    "PriceMessage": "",
    "InStockMessage": "",
    "OutOfStockMessage": "",
    "Variations": "",
    "Attributes": "",
    "Delete": "False"
  },

As you can see, there’s actually html in the long description. Sometimes there’s a table with data or specifications.

To reiterate one last time, I want to give each product a separate page, and a unique URL., but without the path existing on the fileystem- using only a database as I have described.

At this time, you need one content page to generate one output page with its own permalink. Ref: Build pages from data source · Issue #5074 · gohugoio/hugo · GitHub

1 Like

Great answer, Thanks very much.

I would check this as the solution but I want to know the best alternative approach, since there is no way around having one content page per permalink.

Is it possible to have the content pages be only unique as to their filename and to symlink them to their path on the site, but have the actual content pulled from the data.json?

If that is not possible, I suppose the remaining alternative is to have all the content in the markdown files, OR a bash script i can manually run that would parse the data.json into these files automatically so that when the dstabase is updated, changes made there are reflected in the content pages. I could then symlink products from the ‘all’ category to the other categories and subcategories the item belongs to.

It took me a while to find this again… I guess it’s an option?

my 2c as an old senior IT :wink:

  • generate a page for every product, you can create diffent section for different product groups
  • use product id as filename - no collisions
  • make extensive use of taxonomies (partnumber, manufacturer, categories, producttype etc…)
  • use frontmatter parameters for product information
  • if needed use frontmatter - layout for different page layouts

search here for shop extensions, same for formular

hope this helps

3 Likes

The moment you are using a database for something is the moment you should know that it’s not something that you want to create with a STATIC SITE GENERATOR. Don’t get me wrong: you probably will be able to create whatever you want to achieve with Hugo, but: do you want to? No, you don’t. A “catalogue” page is not something that you should do with Hugo.

The same way as you won’t buy a Mercedes car to play your cassette tapes.

/community, /drugs, and /FAQ sections on PsychedelicsDaily.com are generated from a Database, as .md (markdown) files which then hugo builds.

For example, here is one of my templates:

$data = <<<EOT
+++
author = "hash"
authors = "hash-borgir"
banner = "img/molecules/$moleculeSVG"
categories = ["Drug Facts"$tags]
date = "2020-04-20T14:31:41-06:00"
description = "$description"
featured=false
images = ["/img/molecules/$moleculePNG"]
reviewCount = ""
tags = ["Drug Facts", "Molecules"$tags]
title = "{$drug['name']} "

aliases = [
    "/{$drug['name']}"
]

+++

$rc
$psy
$common
$disclaimer

# Description
{$drug['name']}
Also known as:
$names
{$drug['summary']}

$intro
$history

# Chemistry

$smiles

$chemistry
$chemspider

{{< signup>}}

$dose
$duration
$interaction
$general

$effectsAuditory
$effectsCognitive
$effectsPharma
$effectsPhysical
$effectsSensory
$effectsSubjective
$effectsTranspersonal
$effectsVisual

$legal

All the variables are populated with required data before the .md content is generated, and hundreds of pages are generated. Then ‘hugo build’ takes care of the rest.

Until we can make pages from Data, this is all I could find that actually works.

Hope that helps.

1 Like

I’m overwhelmed by all these very good answers and insights. My sincere appreciation goes out to everyone in this thread.

@ pkollitsch I would have liked your insights on what you think a suitable alternative might be. Perhaps you are right but I’m not sure there really is a better tool than hugo right now to try this with.

@sephore gomplate looks very promising and I will have to investigate this more in the future for this application.

@ju52 solid answer as well.

@Hash_Borgir That’s approximately what I was looking for. I would love to have a look at your source. And that’s quite a nice and informative site!

Sure. For example, I have a table called faq, where questions and answers live, so for example:

<?php

function slugify($string) {
    return strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $string), '-'));
}
function contains($needle, $haystack) {
    return stripos($haystack, $needle) !== false;
}

require_once "vendor/autoload.php";

use \RedBeanPHP\R;

R::setup(
    'mysql:host=localhost;dbname=faq',
    'user',
    'pass'
);

$json = R::getAll("SELECT * FROM faq WHERE answer != ''");

foreach ($json as $j) {

    $date = date('c');
    $banner = rand(1, 300);
    $title = str_replace("\"", "'", trim($j['question']));
    $description = str_replace("\"", "'", trim(substr($j['answer'], 0, 80) . '...'));
    $content = trim($j['answer']);

    $sources = '';

    $data = <<<EOT

+++
author = "hash"
authors = "hash-borgir"
banner = "img/banners/dream/$banner.jpg"
categories = ["FAQ"]
date = "$date"
description = "$description"
featured = false
draft=false
images = ["img/og/dream/$banner.jpg"]
keywords = [""]
reviewCount = "$banner"
tags = ["Frequently Asked Questions"]
title = "$title"

+++

# $title

$content


EOT;

    if (!empty($j['answer'])) {
        file_put_contents("$PATH/psychedelicsdaily.com-hugo/content/faq/" . slugify($title) . ".md", $data);
        echo "$PATH/psychedelicsdaily.com-hugo/content/faq/" . slugify($title) . ".md" . PHP_EOL;
    }
}

It’s really as simple as that.

The generated .md file for example would be

are-psychedelics-safe-to-use.md


+++
author = "hash"
authors = "hash-borgir"
banner = "img/banners/dream/150.jpg"
categories = ["FAQ"]
date = "2020-08-13T06:16:33-06:00"
description = "According to the head of a drug research organization, the use of psychedelic dr..."
featured = false
draft=false
images = ["img/og/dream/150.jpg"]
keywords = [""]
reviewCount = "150"
tags = ["Frequently Asked Questions"]
title = "Are psychedelics safe to use?"

+++

# Are psychedelics safe to use?

According to the head of a drug research organization, the use of psychedelic drugs is no more dangerous than cycling, playing football, or smoking cigarettes. 

He says that 30 million adults in the US have tried psychedelics and there is no evidence that they do any harm, but certain drugs could be useful in reducing dependence on other, more harmful substances. This is contrary to human rights, and compared to alcohol and other controlled substances, psychedelic drugs are much less harmful to human health than other drugs, says Dr. John Johansen, director of the Psychedelics Recovery Centre at the University of California, San Diego. These kinds of narratives are common among the people who participate in our recreational groups, as psychedelic consumption is considered a relapse and can push them to the substances that have caused them the most problems, such as alcohol. 

Studies have highlighted how MDMA - assisted psychotherapy - could be used to help people suffering from various forms of PTSD. A 2012 study published in the Journal of Psychopharmacology highlights how LSD and psilocybin could potentially be used to treat alcohol addiction. 

Similar to ayahuasca, brain scans have shown that psilocybin can suppress activity in the brain's standard mode network, and people who stumble across shrooms report experiencing high levels of happiness and belonging to the world. Recent research could prove the potential of psilocybin for the treatment of depression and other mental illnesses. Psilocin has thrilled researchers because it has shown time and again that it can help people with depression. 

The Lancet found that high doses of mushrooms reduced depressive symptoms in treatment-resistant patients. These psychological benefits have led researchers to believe that psychedelics could be an effective therapeutic treatment. 

Indeed, many studies have found that one way or another, all four drugs have the potential to treat a wide range of mental disorders, including depression, anxiety, schizophrenia, and bipolar disorder. 

Microdosing with certain psychedelics is said to induce physical and mental stimulation, improve mood, promote creative thinking, and induce relaxation. Recent studies support the idea that hallucinogenic drugs such as ayahuasca, DMT, MDMA, psilocybin mushrooms, or even diazepam can be used to treat depression, anxiety, post-traumatic stress disorder (PTSD), and other mental illnesses. 

# Sources

https://theoakstreatment.com/drug-rehab/recovery-drugs-dangers/ 

https://interestingengineering.com/everything-you-need-to-know-about-psychedelic-assisted-therapy 

https://www.rollingstone.com/culture/culture-news/what-psychedelics-really-do-to-your-brain-112948/ 

https://www.verywellmind.com/why-do-people-take-hallucinogens-63388 

https://psychedelicstoday.com/2020/04/08/psychedelics-addiction-recovery/ 

https://www.independent.co.uk/news/world/psychedelic-drugs-as-safe-as-riding-a-bike-or-playing-soccer-and-could-help-solve-addiction-10161432.html 

https://www.addictioncenter.com/drugs/hallucinogens/lsd-addiction/microdosing-lsd/

Hugo takes over from here, with hugo build

                  |  EN   
-------------------+-------
 Pages            |  849  
 Paginator pages  |   12  
 Non-page files   |   28  
 Static files     | 2014  
 Processed images |    0  
 Aliases          |  390  
 Sitemaps         |    1  
 Cleaned          |    0  
                          
Total in 12400 ms          

Here’s a little more involved example.

<?php
function contains($needle, $haystack) {
    return stripos($haystack, $needle) !== false;
}
function slugify($string) {
    return strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $string), '-'));
}
require_once "vendor/autoload.php";
use \RedBeanPHP\R;


R::setup(
    'mysql:host=localhost;dbname=community',
    'stoned',
    'ape'
);

$sql = R::getRow("SELECT group_concat(DISTINCT organisationtype) AS `type` FROM community");

$types = explode(",", $sql['type']);

foreach ($types as $type){
    $communities = R::getAll("SELECT * FROM community WHERE organisationtype = '$type'");

    $num = rand(1,420);
    $date = date('c');

    if ($type == 'Psychedelic Society'){
        $title = "Connect with a $type near you.";
        $desc = "Comprehensive list of Psychedelic Societies";
    }
    if ($type == 'Service provider'){
        $title = "Psychedelic Service Providers List";
        $desc = "Comprehensive list of Psychedelic Service Providers.";
    }
    if ($type == 'Non Profit Organization'){
        $title = "Psychedelic $type List";
        $desc = "Comprehensive list of Psychedelic Non Profit Organizations";
    }
    if ($type == 'Media'){
        $title = "Psychedelic $type Companies List";
        $desc = "Comprehensive list of Psychedelic $type Compaines";
    }
    if ($type == 'Harm Reduction'){
        $title = "Psychedelic $type List";
        $desc = "Comprehensive $type Compaines List";
    }
    if ($type == 'Conferences / Events'){
        $title = "Psychedelic Conferences & Events Organizations";
        $desc = "Comprehensive Conferences & Events Organizations";
    }
    if ($type == 'Educational Program'){
        $title = "Psychedelic $type List";
        $desc = "Comprehensive $type List";
    }
    if ($type == 'Campaign Initiative'){
        $title = "Psychedelic $type List";
        $desc = "Comprehensive $type List";
    }

    $path = "/home/stoned/websites/websites/psychedelicsdaily.com-hugo/content/community/";
    $filename = slugify($title);

    $md = <<<EOT
+++
author = "hash"
authors = "hash-borgir"
title="$title"
date = "$date"
banner = "img/banners/dream/$num.jpg"
images = ["img/banners/dream/$num.jpg"]
description = "$desc"
keywords = ["Community $type"]
reviewCount = "147"
tags = ["Community"]
+++


EOT;


    foreach ($communities as $c) {

        if (!empty($c['ogimage'])){
            $ogimage = "{{<imgcap src=\"{$c['ogimage']}\">}}";
        } else {
            $ogimage = "";
        }

        $md .= <<<EOT

# {$c['name']}

{$c['description']}

$ogimage

* {$c['city']}/ [{$c['country']}]

* {$c['website']}

* {$c['facebook']}

* {$c['othersocialmedia']}

<hr style="margin-top: 60px; margin-bottom: 60x;">

EOT;


        file_put_contents($path.$filename.".md", $md);
        echo "$filename.md" . PHP_EOL;
    } // end inner loop

} // end outer loop


/content/community/psychedelic-education-program-list.md

+++
author = "hash"
authors = "hash-borgir"
title="Psychedelic Educational Program List"
date = "2020-06-16T16:16:45-06:00"
banner = "img/banners/dream/271.jpg"
images = ["img/banners/dream/271.jpg"]
description = "Comprehensive Educational Program List"
keywords = ["Community Educational Program"]
reviewCount = "147"
tags = ["Community"]
+++


# School for Advanced Studies in the Social Sciences





* Paris/ [France]

* https://enseignements-2019.ehess.fr/2019/ue/2998/


<hr style="margin-top: 60px; margin-bottom: 60x;">

# CIIS Center for Psychedelic Therapies and Research





* San Francisco/ [United States]

* https://www.ciis.edu/cptr

* https://www.facebook.com/ciissf

* https://twitter.com/@ciis_sf

<hr style="margin-top: 60px; margin-bottom: 60x;">

# JFK University





* Sunnyvale/ [United States]

* https://www.jfku.edu

* https://www.facebook.com/JFKUniv

* https://www.linkedin.com/school/john-f.-kennedy-university/

<hr style="margin-top: 60px; margin-bottom: 60x;">

# Fluence





* New York City/ [United States]

* https://www.fluence8.com/


<hr style="margin-top: 60px; margin-bottom: 60x;">

hugo build takes over from here.

This one is a little more involved still, for the community pages for country/state/city/

<?php
function contains($needle, $haystack) {
    return stripos($haystack, $needle) !== false;
}
function slugify($string) {
    return strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $string), '-'));
}
require_once "vendor/autoload.php";

use DivineOmega\Countries\Countries;
use \RedBeanPHP\R;

R::setup(
    'mysql:host=localhost;dbname=community',
    'stoned',
    'ape'
);

$json = R::getAll("SELECT * FROM community");

foreach ($json as $j) {
    $date = date('c');
    $img = rand(1, 429);

    if (!empty($j['othersocialmedia'])) {
        $sm = "<a href='{$j['othersocialmedia']}'>{$j['othersocialmedia']}</a>";
    } else {
        $sm = '';
    }

    if (!empty($j['stateprovince'])) {
        $sp = "{$j['stateprovince']}, ";
    } else {
        $sp = '';
    }

    if (!empty($j['website'])) {
        $ws = "<a href='{$j['website']}'>{$j['website']}</a>";
    } else {
        $ws = '';
    }

    if (!empty($j['facebook'])) {
        $fb = "<a href='{$j['facebook']}'>{$j['facebook']}</a>";
    } else {
        $fb = '';
    }

    if (!empty($j['city'])) {
        $city = "{$j['city']}, ";
    } else {
        $city = '';
    }

    if (!empty($j['notes'])) {
        $notes = "{$j['notes']}";
    } else {
        $notes = '';
    }

    $country = "{$j['country']}";
    $org = "{$j['organisationtype']}";

    $name = slugify($j['name']);
    $countrySlug = slugify($j['country']);
    $stateSlug = slugify($j['stateprovince']);

    if (!empty($j['othersocialmedia']) && contains("twitter", $j['othersocialmedia'])) {
        $twHandle = str_replace("https://twitter.com/@", "", $j['othersocialmedia']);
        $twitter = '<div class="center" style="width: 80%; margin: 0 auto;"><p class="h1">Follow <a href="htts://twitter.com/$ogtwitter">'.$ogtwitter.'</a></p><a class="twitter-timeline" href="https://twitter.com/' . $twHandle . '?ref_src=twsrc%5Etfw">Tweets by ' . $twHandle . '</a> <script src="https://platform.twitter.com/widgets.js" charset="utf-8"></script></div>';
    } else {
        $twitter = '';
    }

    if (!empty($j['facebook'])) {
        $fbHandle = str_replace("https://www.facebook.com/", "", $j['facebook']);

        if (contains("groups", $j['facebook'])){
            $facebook = <<<EOT
            <p class="h1">Join {$j['name']} Group</p>
<div class="fb-group" data-href="{$j['facebook']}" data-width="380" data-show-social-context="true" data-show-metadata="true"></div>
EOT;
        } else {
$facebook = <<<EOT
<div class="center">
<div class="fb-page" data-href="https://www.facebook.com/$fbHandle" data-tabs="timeline" data-width="" data-small-header="false" data-adapt-container-width="true" data-hide-cover="false" data-show-facepile="true"><blockquote cite="https://www.facebook.com/$fbHandle" class="fb-xfbml-parse-ignore"><a href="https://www.facebook.com/$fbHandle">$fbHandle</a></blockquote></div>
</div>
EOT;
        }

    } else {
        $facebook = '';
    }

    if (!empty($j['country']) && $j['country'] != "Global") {
        $countryFlag = strtolower((new Countries)->getByName($j['country'])->isoCodeAlpha2);
    } else if ($j['country'] == "Global") {
        $countryFlag = "global";
    } else {
        $countryFlag = "global";
    }

    $countryName=$j['country'];
    $cityName=$j['city'];
    if (empty($j['stateprovince'])) {
        $stateprovince = "{$j['country']}";
        $banner = "\"img/flags/$countryFlag.svg\"";
        $images = "[\"img/flags/$countryFlag.svg\"]";
    } else {
        $stateprovince = "{$j['stateprovince']}";
        $banner = "\"img/banners/dream/$img.jpg\"";
        $images = "[\"img/banners/dream/$img.jpg\"]";
    }
    $_indexCountry = <<<EOT
+++
title="{$j['country']} Psychedelic Communities"
banner = "img/flags/$countryFlag.svg"
images = ["img/flags/$countryFlag.svg"]
description = "Find support, integration, and harm reduction psychedelic communities in {$j['country']}"
+++

# Psychedelics Groups of $countryName

<p style="padding: 1em;" class="alert alert-danger">Disclaimer: We do not condone or comment on the quality of any of these groups, clubs, societies, communities or other types of gatherings. We are only providing this information here for you to explore.</p>

This is a comprehensive list of all the psychedelic communities I could find.

{{< map location="$countryName" zoom="5">}}

EOT;

    if (!empty($ws)){
        $ws = <<<EOT
<div class="shadow row">
<div class="col-md-2">
<img src="/img/community/website.svg"  />
</div>
<div class="col-md-8 h3">
$ws
</div>
</div>
EOT;
    }
    if (!empty($fb)){
        $fb= <<<EOT
<div class="shadow row">
<div class="col-md-2">
<img src="/img/community/facebook.svg"  />
</div>
<div class="col-md-8 h3">
$fb
</div>
</div>
EOT;
    }
    if (!empty($sm)){
        $sm= <<<EOT
<div class="shadow row">
<div class="col-md-2">
<img src="/img/community/othersocialmedia.svg"  />
</div>
<div class="col-md-8 h3">
$sm
</div>
</div>
EOT;
    }
    if (!empty($j['ogimage'])){
        $ogimage = "{{<imgcap src=\"{$j['ogimage']}\">}}";
    }

    if (!empty($j['twitter']) || $j['twitter'] != "@meetup"){
        $ogtwitter = $j['twitter'];
    }
    if (!empty($j['modified'])){
        $modified = "<p>Modified: {$j['modified']}</p>";
    }
    $_indexState = <<<EOT
+++
title="$stateprovince Psychedelic Communities"
banner = $banner
images = $images
description = "Find support, integration, and harm reduction psychedelic communities in $stateprovince"
+++

# Psychedelics Groups of $stateprovince

<p style="padding: 1em;" class="alert alert-danger">Disclaimer: We do not condone or comment on the quality of any of these groups, clubs, societies, communities or other types of gatherings. We are only providing this information here for you to explore.</p>

This is a comprehensive list of all the psychedelic communities I could find.

{{< map location="$stateprovince" zoom="6">}}

EOT;
    $data = <<<EOT
+++
author = "hash"
authors = "hash-borgir"
banner = "img/banners/dream/$img.jpg"
categories = ["Community"]
date = "$date"
description = "{$j['country']}, {$j['stateprovince']} {$j['city']}"
featured = false
images = ["img/og/dream/$img.jpg"]
keywords = ["Community"]
reviewCount = "147"
tags = ["Community"]
title = "{$j['name']}"
+++

# {$j['name']}

{$j['description']}



Find someone to connect with locally. Please reach out to them and connect.

<div class="community-info">
<div class="shadow row">
<div class="col-md-2">
<img src="/img/community/earth.svg"  />
</div>
<div class="col-md-8 h3">
$city $sp $country
</div>
</div>

$fb

$ws

$sm

<div class="shadow row">
<div class="col-md-2">
<img src="/img/community/note.svg"  />
</div>
<div class="col-md-8 h3">
$notes

$modified



</div>
</div>

<div class="shadow row">
<div class="col-md-2">
<img src="/img/community/org.svg"  />
</div>
<div class="col-md-8 h3">
$org
</div>
</div>

</div>

{{< map location="$stateprovince" zoom="8">}}

<div class="facebook center" style="margin-top: 60px;">
$facebook
</div>
<div class="twitter center" style="margin-top: 60px;">



$twitter

</div>



<br style='margin-top: 60px;'>
EOT;

    // if there is no state, save under country else save under country/state/

    $path = "/home/stoned/websites/websites/psychedelicsdaily.com-hugo/content/community/";

    if (empty($j['stateprovince'])) {
        @mkdir("$path/$countrySlug/$name", 0755, true);
        $filename = "$path/$countrySlug/_index.md";
        file_put_contents($filename, $_indexCountry);
        $filename = "$path/$countrySlug/$name/index.md";@
        file_put_contents($filename, $data);
    } else {
        $filename = "$path/$countrySlug/_index.md";
        file_put_contents($filename, $_indexCountry);
        @mkdir("$path/$countrySlug/$stateSlug/$name", 0755, true);
        $filename = "$path/$countrySlug/$stateSlug/_index.md";
        file_put_contents($filename, $_indexCountry);
        $filename = "$path/$countrySlug/$stateSlug/$name/index.md";
        file_put_contents($filename, $data);
    }

    $filename = "$path/$countrySlug/$stateSlug/_index.md";
    file_put_contents($filename, $_indexState);

    $x = R::load("community", $j['id']);
    $url = "/community/$countrySlug/$stateSlug/$name";

    $x['url'] = $url;

    R::store($x);

    $main_index = <<<EOT
+++
title=" Psychedelic Communities"
banner = "img/flags/global.svg"
images = ["img/flags/global.svg"]
description = "Find support, integration, and harm reduction psychedelic communities globally."
+++

# Psychedelics Groups of The World

Disclaimer: We do not condone or comment on the quality of any of these groups, clubs, societies, communities or other types of gatherings. We are only providing this information here for you to explore.

This is a comprehensive list of all the psychedelic communities I could find.
tab-pane

EOT;
    $filename = "$path/_index.md";
    file_put_contents($filename, $main_index);
}

/home/stoned/websites/websites/psychedelicsdaily.com-hugo/content/community/united-states/oregon/psilocybin-services-initiative/index.md

+++
author = "hash"
authors = "hash-borgir"
banner = "img/banners/dream/70.jpg"
categories = ["Community"]
date = "2020-06-16T16:13:46-06:00"
description = "United States, Oregon Portland"
featured = false
images = ["img/og/dream/70.jpg"]
keywords = ["Community"]
reviewCount = "147"
tags = ["Community"]
title = "Psilocybin Services Initiative"
+++

# Psilocybin Services Initiative

Find someone to connect with locally. Please reach out to them and connect.

<div class="community-info">
<div class="shadow row">
<div class="col-md-2">
<img src="/img/community/earth.svg"  />
</div>
<div class="col-md-8 h3">
Portland,  Oregon,  United States
</div>
</div>

<div class="shadow row">
<div class="col-md-2">
<img src="/img/community/facebook.svg"  />
</div>
<div class="col-md-8 h3">
<a href='https://www.facebook.com/yesonip34/'>https://www.facebook.com/yesonip34/</a>
</div>
</div>

<div class="shadow row">
<div class="col-md-2">
<img src="/img/community/website.svg"  />
</div>
<div class="col-md-8 h3">
<a href='https://yesonip34.org/'>https://yesonip34.org/</a>
</div>
</div>

<div class="shadow row">
<div class="col-md-2">
<img src="/img/community/othersocialmedia.svg"  />
</div>
<div class="col-md-8 h3">
<a href='https://www.instagram.com/yesonip34/'>https://www.instagram.com/yesonip34/</a>
</div>
</div>

<div class="shadow row">
<div class="col-md-2">
<img src="/img/community/note.svg"  />
</div>
<div class="col-md-8 h3">
Updated 3/29/20

<p>Modified: 2019-12-19T22:26:49+00:00</p>

</div>
</div>

<div class="shadow row">
<div class="col-md-2">
<img src="/img/community/org.svg"  />
</div>
<div class="col-md-8 h3">
Campaign Initiative
</div>
</div>

</div>

{{< map location="Oregon" zoom="8">}}

<div class="facebook center" style="margin-top: 60px;">
<div class="center">
<div class="fb-page" data-href="https://www.facebook.com/yesonip34/" data-tabs="timeline" data-width="" data-small-header="false" data-adapt-container-width="true" data-hide-cover="false" data-show-facepile="true"><blockquote cite="https://www.facebook.com/yesonip34/" class="fb-xfbml-parse-ignore"><a href="https://www.facebook.com/yesonip34/">yesonip34/</a></blockquote></div>
</div>
</div>
<div class="twitter center" style="margin-top: 60px;">

</div>

<br style='margin-top: 60px;'>

Again, hugo build takes over from here.

Basically, you’re using whatever platform/language/db engine to generates markdown content files in $PROJECT/content/*.md

Then hugo builds that. I hope that helps.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.