Giter Club home page Giter Club logo

Comments (10)

fscherf avatar fscherf commented on June 30, 2024

hi @Lowell130,

what do you mean? Do you want to use JSON for your meta data, or do you want to add complete content files containing JSON?

In both cases you would need to add a new flamingo parser. I currently write documentation on how to do it, and could provide you a snippet to start with

from flamingo.

Lowell130 avatar Lowell130 commented on June 30, 2024

hi @Lowell130,

what do you mean? Do you want to use JSON for your meta data, or do you want to add complete content files containing JSON?

In both cases you would need to add a new flamingo parser. I currently write documentation on how to do it, and could provide you a snippet to start with

i just want generate static HTML pages by JSON data, it's possible?

from flamingo.

fscherf avatar fscherf commented on June 30, 2024

Flamingo has no native support for JSON files. You would need to write a plugin with ~10 lines of code i think. But then you can use JSON files. So yes and no.

from flamingo.

fscherf avatar fscherf commented on June 30, 2024

@Lowell130 does this answer your question?

from flamingo.

Lowell130 avatar Lowell130 commented on June 30, 2024

@Lowell130 does this answer your question?

i know how fetch json data by JS for SPA (sigle page application) web site but i don't know how do that to generate static page, can you help me?

from flamingo.

fscherf avatar fscherf commented on June 30, 2024

Ah ok! If i understand you correctly, you want to create one HTML page as singe page application and store all contents as JSON files to load them from the HTML page using JS?

In this case you can do something like this:

class SinglePageApplicationPlugin:
    def contents_parsed(self, context):
        data = []

        for content in context.contents:
            data.append({
                'title': content['content_title'],
                'body': content['content_body'],
            })

        json.dumps(data)

from flamingo.

Lowell130 avatar Lowell130 commented on June 30, 2024

Ah ok! If i understand you correctly, you want to create one HTML page as singe page application and store all contents as JSON files to load them from the HTML page using JS?

In this case you can do something like this:

class SinglePageApplicationPlugin:
    def contents_parsed(self, context):
        data = []

        for content in context.contents:
            data.append({
                'title': content['content_title'],
                'body': content['content_body'],
            })

        json.dumps(data)

not exactly i just want generate html pages for each item stored in my json. In my json i have lots of items with their key value infos, there e sample of json file: https://easyupload.io/nqhnc2

from flamingo.

fscherf avatar fscherf commented on June 30, 2024

ah ok! Then you could should write a parser

import json

from flamingo.core.parser import ContentParser


class JSONParser(ContentParser):
    FILE_EXTENSIONS = ['json']

    def parse(self, file_content, content):
        for entry in json.loads(file_content):
            content['content_title'] = entry['title']
            content['content_body'] = entry['body']


class JSON:
    def parser_setup(self, context):
        context.parser.add_parser(JSONParser(context))

from flamingo.

Lowell130 avatar Lowell130 commented on June 30, 2024

ah ok! Then you could should write a parser

import json

from flamingo.core.parser import ContentParser


class JSONParser(ContentParser):
    FILE_EXTENSIONS = ['json']

    def parse(self, file_content, content):
        for entry in json.loads(file_content):
            content['content_title'] = entry['title']
            content['content_body'] = entry['body']


class JSON:
    def parser_setup(self, context):
        context.parser.add_parser(JSONParser(context))

wow please give me time to check your great solution

from flamingo.

fscherf avatar fscherf commented on June 30, 2024

Hi @Lowell130,

This issue is still open. Did my example solve your problem?

from flamingo.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.