Dynamic Content Management

Understanding how content is structured and managed in NestSaaS

NestSaaS uses a flexible content model centered around Articles, with metadata that adapts to different content types. This approach allows you to manage diverse content through a unified interface while maintaining the specific characteristics needed for each content type.

Content Model

The core of NestSaaS's content management is the Article model, which provides a flexible structure for all types of content.

Article Structure

Each Article includes:

  • Core Fields: Standard fields available for all content
  • Metadata: Flexible JSON fields that vary based on the Space type
  • Relationships: Connections to categories, tags, and other entities

Core Fields

All Articles include these standard fields:

FieldTypeDescription
idnumberUnique identifier
spaceSlugstringAssociated Space slug
slugstringURL-friendly identifier
titlestringArticle title
excerptstringBrief summary
contentstringMain content (stored as html text)
statusenumPublication status
ordernumberSort order
featuredboolean?Featured
protectedboolean?Protected access
coverImagestring?Cover image URL
blurhashstring?Cover image blurhash
websitestring?Cover image blurhash
draftjson?content draft for block editor
metadataJSONFlexible metadata fields
createdAtdateCreation timestamp
updatedAtdateLast update timestamp
publishedAtdatePublication timestamp
categoryIdnumberPrimary category ID
authorIdnumberUser ID

Content Status

Articles can have different statuses throughout their lifecycle:

  • DRAFT: Work in progress, not publicly visible
  • APPLICATION: Submitted for review (for user submissions)
  • APPROVED: Submission that was approved
  • REJECTED: Submission that was not approved
  • PUBLISHED: Live and publicly accessible
  • ARCHIVED: No longer active but preserved
  • HIDDEN: Temporarily hidden from public view

Metadata

The metadata field is a flexible JSON structure that stores Space-specific fields. The structure of this metadata is defined by the Space configuration.

Example metadata for a product:

{
  "productId": "Prod123",
  "priceId": "pi_xxx",
  "price": 5,
  "dimensions": "15x30"
}

Example metadata for a restaurants listing:

{
  "address": "123 Main St, City, Country",
  "phone": "+1-234-567-8900",
  "rating": 4.5,
  "priceRange": "$$",
  "openingHours": {
    "monday": "9:00-17:00",
    "tuesday": "9:00-17:00",
    "wednesday": "9:00-17:00",
    "thursday": "9:00-17:00",
    "friday": "9:00-17:00",
    "saturday": "10:00-15:00",
    "sunday": "Closed"
  }
}

Content Editor

NestSaaS includes a powerful block-based content editor similar to Notion, allowing you to create rich, structured content.

Content Management

Creating Content

Content is created through the admin interface:

  1. Select the Space where you want to create content
  2. Click "New Article" (or the Space-specific label)
  3. Fill in the core fields (title, excerpt, etc.)
  4. Add content using the block editor
  5. Complete the metadata fields specific to the Space
  6. Set the category and tags
  7. Save as draft or publish immediately

Editing Content

The editing process includes:

  • Modify any field of existing article
  • Delete an existing article

Publishing Workflow

NestSaaS supports flexible publishing workflows:

  • Simple: Draft → Published
  • User Submissions: Application → Review → Published/Rejected

Content Protection(Not Currently, Future support)

Articles can be protected with different access controls:

  • Public: Accessible to everyone
  • Member: Requires user account
  • Paid: Requires subscription or purchase
  • Custom: Programmatic access control based on user attributes

Server Actions

// Create an article
async function createArticle(data) {
  const article = await prisma.article.create({
    data: {
      title: data.title,
      slug: data.slug,
      content: data.content,
      excerpt: data.excerpt,
      coverImage: data.coverImage,
      status: data.status,
      spaceId: data.spaceId,
      categoryId: data.categoryId,
      userId: data.userId,
      metadata: data.metadata,
    },
  });
  
  return article;
}
 
// Update an article
async function updateArticle(id, data) {
  const article = await prisma.article.update({
    where: { id },
    data,
  });
  
  return article;
}
 
// Delete an article
async function deleteArticle(id) {
  await prisma.article.delete({
    where: { id },
  });
  
  return { success: true };
}

Querying Content

NestSaaS provide queries in the server actions actions/article-actions.ts

  • getArticles( spaceSlug: string, filter: ArticleFilter = {}, sort: ArticleSortBy = [{ featured: "desc" }, { publishedAt: "desc" }], pagination?: ArticlePagination)
  • getArticleBySlug(spaceSlug, slug)
  • getRelatedArticles(spaceSlug: string, articleId: number, limit = 3)
  • getPopularArticles(spaceSlug: string, limit = 5)
  • getLatestArticles(spaceSlug: string, limit = 5)
  • getArticlesByCategory(spaceSlug: string, categorySlug: string, pagination?: ArticlePagination)
  • getArticlesByTag(spaceSlug: string, tagSlug: string, pagination?: ArticlePagination)

NestSaaS includes built-in full-text search capabilities, we create a GIN index for faster full-text search.

Adds full-text search capabilities to the articles table:

  • Adds a searchVector column of type tsvector
  • Creates a GIN index for faster full-text search
  • Sets up a trigger to automatically update the search vector when articles are inserted or updated
  • Updates existing records with search vectors

and then you can excute full-text search on articles:

SELECT * FROM articles
WHERE "searchVector" @@ to_tsquery('english', 'your search terms')
ORDER BY ts_rank("searchVector", to_tsquery('english', 'your search terms')) DESC;

Best Practices

  1. Use Meaningful Titles and Slugs: Create clear, descriptive titles and SEO-friendly slugs.

  2. Optimize Cover Images: Use high-quality images that represent your content well.

  3. Write Good Excerpts: Craft compelling excerpts that summarize your content and encourage clicks.

  4. Structure Content with Blocks: Use the block editor to create well-structured, scannable content.

  5. Complete Metadata: Fill in all relevant metadata fields to enhance searchability and functionality.

  6. Categorize Properly: Assign appropriate categories and tags to improve content organization.

  7. Preview Before Publishing: Always preview your content on different devices before publishing.

Next Steps

On this page