Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable mixed content in the API pages directory #1246

Open
thescientist13 opened this issue Jun 21, 2024 · 0 comments
Open

enable mixed content in the API pages directory #1246

thescientist13 opened this issue Jun 21, 2024 · 0 comments
Labels
CLI documentation Greenwood specific docs feature New feature or request SSR
Milestone

Comments

@thescientist13
Copy link
Member

thescientist13 commented Jun 21, 2024

Summary

Coming out of #955 / #1212, one follow up item was that after the change to collapsing down the API directory into the page directory, instead of being its own top level directory

src/
  pages/
    api/
      search.js   

A question of mixed content came up as a discussion around that topic, which basically came down to, what if you actually wanted pages in that directory? Like for actual API documentation.

src/
  pages/
    api/
      index.html  

Details

So we could easily support this for static pages, e.g. markdown and HTML, just like we detect normal pages. But what happens if you actually wanted a server / pre-rendered page, like say for building up a table of contents, or auto generating docs, e.g.

// src/pages/api/index.js
import fs from 'fs/promises';

export default class ApiDocsPage extends HTMLElement {
  
  connectedCallback() {
    // could also come through the graph as constructor props
    const pages = await fs.promises.readDir('./.').filter(file => file.split('.').pop() === 'md'));
    
    this.innerHTML = `
      <h1>Table of Contents</h1>
        <nav>
          <ol>
            ${ 
              pages.map((page) => {
                const name = page.replace('.md', '');
              
                return `<li><a href="/${name}/">${name}</a></li>`; 
              }).join('')
            }
         </ol>
       </nav>
     `;
   }
}

How would / could Greenwood specifically detect this case vs just any other API route? Basically, have Greenwood support all these use cases at once

src/
  pages/
    api/
      search.js // classic API route
      index.html // static page
      docs.js // SSR page

Most naive approach could be to just have SSR pages in the API directory export a flag, which we already support?

https://www.greenwoodjs.io/docs/server-rendering/#prerender
export const prerender = true;

// or

export const ssr = true;
@thescientist13 thescientist13 added CLI SSR feature New feature or request labels Jun 21, 2024
@thescientist13 thescientist13 added this to the 1.x milestone Jun 21, 2024
@thescientist13 thescientist13 changed the title enabled mixed content in the API pages directory enable mixed content in the API pages directory Jun 21, 2024
@thescientist13 thescientist13 added the documentation Greenwood specific docs label Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLI documentation Greenwood specific docs feature New feature or request SSR
Projects
None yet
Development

No branches or pull requests

1 participant