Skip to content

Commit

Permalink
Add Cocos2d-x feature guides (#1094)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sporiff authored Oct 2, 2024
2 parents a589dc5 + 454e674 commit ac24c2a
Show file tree
Hide file tree
Showing 89 changed files with 3,679 additions and 61 deletions.
2 changes: 2 additions & 0 deletions .github/styles/Microsoft/HeadingAcronyms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ exceptions:
- AAR
- CPU
- IDE
- SKAN
- SKAD
11 changes: 11 additions & 0 deletions .github/styles/config/vocabularies/Adjust/accept.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
MUST
MUST NOT
REQUIRED
SHALL
SHALL NOT
SHOULD
SHOULD NOT
RECOMMENDED
NOT RECOMMENDED
MAY
OPTIONAL
51 changes: 51 additions & 0 deletions .schema/List.markdoc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import markdoc from "@markdoc/markdoc";
const { Tag } = markdoc;

/**
* A function to transform checkbox markers ([ ] and [x]) into checkboxes
* @param children The child elements of the list item
* @returns Updated children with checkboxes added if necessary
*/
function transformListItemChildren(children) {
return children.flatMap((child, index) => {
if (typeof child === 'string' && index === 0) {
if (child.startsWith("[ ]")) {
return [
new Tag("input", { type: "checkbox" }, []),
child.slice(3).trim()
];
} else if (child.startsWith("[x]")) {
return [
new Tag("input", { type: "checkbox", checked: "", }, []),
child.slice(3).trim()
];
}
} else if (child instanceof Tag) {
// Recursively call this function on nested lists
return new Tag(child.name, child.attributes, transformListItemChildren(child.children));
}

return child;
});
}

export const list = {
children: ['item'],
attributes: {
ordered: { type: Boolean, default: false },
marker: { type: String }
},
transform(node, config) {
const attributes = node.transformAttributes(config);
const children = node.transformChildren(config);
// If it's an ordered list, do nothing
if (attributes.ordered) return new Tag("ol", attributes, children.map(child => new Tag("li", {}, child.children)));

// If the list is unordered, apply the transformation
return new Tag("ul", attributes, children.map(child => {
// Transform each list item
const listItemChildren = transformListItemChildren(child.children);
return new Tag("li", {}, listItemChildren);
}));
}
};
3 changes: 3 additions & 0 deletions .vale.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ IgnoredScopes = code, tt, img, url, a
SkippedScopes = script, style, pre, figure, code
MinAlertLevel = warning # suggestion, warning or error

Vocab = Adjust

# Force Vale to treat MDX files as markdown
[formats]
mdx = md
mdoc = md

# Only Markdown and .txt files; change to whatever you're using.
[*.md]
Expand Down
6 changes: 5 additions & 1 deletion markdoc.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ import { defineMarkdocConfig, nodes, component } from '@astrojs/markdoc/config';
import { heading } from ".schema/Heading.markdoc";
import { link } from ".schema/Link.markdoc";
import { paragraph } from ".schema/Paragraph.markdoc";
import { list } from ".schema/List.markdoc";
import versions from "src/versionMap.json";
import variables from "src/variables.json";

export default defineMarkdocConfig({
variables: {
versions
versions,
variables
},
nodes: {
heading,
link,
list,
paragraph,
fence: {
attributes: { ...nodes.fence.attributes },
Expand Down
2 changes: 1 addition & 1 deletion src/components/ListColumns.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const content = Astro.slots.has("default")
? await Astro.slots.render("default")
: "";
const lists = content.split("<hr>");
const lists = content.split(/<hr\/?>/);
---

<div class="col-group grid grid-flow-row lg:grid-flow-col gap-6 mb-7">
Expand Down
91 changes: 56 additions & 35 deletions src/components/utils/parseDefList.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,45 @@
import { unified } from "unified";
import rehypeParse from "rehype-parse";
import rehypeStringify from "rehype-stringify";
import type { Element, Root } from "hast";
import type { Element, Root, Text } from "hast";

/**
* Extracts text content from an element's children recursively.
* @param children The children of the element.
* @returns The concatenated text content.
*/
const getTextContent = (children: (Element | Text)[]): string => {
return children
.map((child) => {
if (child.type === 'text') {
return child.value;
} else if (child.type === 'element') {
// Recursively get the text content of nested elements
return getTextContent(child.children as (Element | Text)[]);
}
return '';
})
.join('');
};

/**
* Checks if a value is a definition list term.
* @param text The text value of the element.
* @param children The children of the element.
* @returns Whether the value of the element is a term.
*/
const isTerm = (text: string): boolean => {
return /^\S[^: ].*$/.test(text.trim());
const isTerm = (children: (Element | Text)[]): boolean => {
const text = getTextContent(children).trim();
return /^\S[^: ].*$/.test(text);
};

/**
* Checks if a value is a definition list description.
* @param text The text value of the element.
* @returns Whether the value of the element is a term.
* @param children The children of the element.
* @returns Whether the value of the element is a description.
*/
const isDescription = (text: string): boolean => {
return /^(:|\s)/.test(text.trim());
const isDescription = (children: (Element | Text)[]): boolean => {
const text = getTextContent(children).trim();
return /^(:|\s)/.test(text);
};

/**
Expand Down Expand Up @@ -53,78 +74,78 @@ export const parseDefList = async (htmlString: string): Promise<string> => {
children.forEach((element) => {
if (element.type === 'element') {
if (element.tagName === 'p') {
const text = element.children
.filter((child): child is Element & { value: string } => child.type === 'text')
.map((child) => child.value)
.join("")
.trim();
const textChildren = element.children as (Element | Text)[];

// Perform this action for each term
if (isTerm(text)) {
// Check if this paragraph contains a term
if (isTerm(textChildren)) {
// If we reach a new term, we need to finish appending the descriptions to the last term we were working on.
if (currentTerm) {
// Add the term to the list
// Push the last term and its descriptions
dlNode.children.push(currentTerm);
// Add all collected descriptions
currentDescription.forEach(dd => dlNode.children.push(dd));
currentDescription = [];
}

// If this is the first term, assign it as the current term.
currentTerm = {
type: "element",
tagName: "dt",
children: [{ type: "text", value: text }],
children: textChildren, // Keep all children, including inline formatting
properties: {},
};
} else if (isDescription(text) && currentTerm) {
// If the element is a description (paragraph starting with whitespace or a colon), add it to the currentDescription array
} else if (isDescription(textChildren) && currentTerm) {
currentDescription.push({
type: "element",
tagName: "dd",
children: [{ type: "text", value: text.replace(/^:/, "").trim() }],
children: [{
type: "element",
tagName: "p",
children: textChildren.map(child => {
if (child.type === 'text') {
// Strip leading colon or whitespace for descriptions
return {
...child,
value: child.value.replace(/^:/, '').trim(),
};
}
return child;
}),
properties: {},
}],
properties: {},
});
}
} else {
// If the element isn't a paragraph tag, it will be a description
// Non-paragraph elements are considered descriptions
if (currentTerm) {
// If we have an ongoing term, finalize it
dlNode.children.push(currentTerm);
currentTerm = null;
// Add all collected descriptions
currentDescription.forEach(dd => dlNode.children.push(dd));
currentDescription = [];
}

// Wrap all elements that aren't a paragraph in a <dd> tag
const ddElement: Element = {
type: "element",
tagName: "dd",
children: [element],
children: [element], // Wrap the non-paragraph element
properties: {},
};
// Add the description element to the definition list
dlNode.children.push(ddElement);
}
}
});

// Finalize the last term-description pair if it exists
// Finalize the last term-description pair
if (currentTerm) {
dlNode.children.push(currentTerm);
if (currentDescription.length > 0) {
currentDescription.forEach(dd => dlNode.children.push(dd));
}
currentDescription.forEach(dd => dlNode.children.push(dd));
}

// Overwrite the entire tree with the new <dl> node
// Replace the tree with the new <dl> node
tree.children = [dlNode];
};
})
.use(rehypeStringify); // Convert the result to a string so we can use set:html
.use(rehypeStringify);

// Process and return the transformed HTML
const result = await processor.process(htmlString);
return String(result);
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@
title: Configuration
description: Follow the guides in this section to configure the Adjust SDK.
category-title: Configuration
slug: en/sdk/cocos2dx/configuration
slug: en/sdk/cocos2dx/v4/configuration
sidebar-position: 1
versions:
- label: v5
value: v5
default: true
- label: v4
value: v4
redirects:
v5: /en/sdk/cocos2dx/configuration
---

Use the methods in this document to configure the behavior of the Adjust SDK.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
---
title: Send ad revenue information
description: Send ad revenue information for supported network partners using the Adjust SDK.
slug: en/sdk/cocos2dx/features/ad-revenue
slug: en/sdk/cocos2dx/v4/features/ad-revenue
versions:
- label: v5
value: v5
default: true
- label: v4
value: v4
redirects:
v5: /en/sdk/cocos2dx/features/ad-revenue
---

You can record ad revenue for [supported network partners](https://help.adjust.com/en/article/ad-revenue) using the Adjust SDK.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
---
title: Set up App Tracking Transparency
description: Configure your app to use Apple's App Tracking Transparency framework
slug: en/sdk/cocos2dx/features/att
slug: en/sdk/cocos2dx/v4/features/att
versions:
- label: v5
value: v5
default: true
- label: v4
value: v4
redirects:
v5: /en/sdk/cocos2dx/features/att
---

If you want to record the device's ID for Advertisers (IDFA), you must display a prompt to get your user's authorization. To do this, you need to include Apple's App Tracking Transparency (ATT) framework in your app. The Adjust SDK stores the user's authorization status and sends it to Adjust's servers with each request.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
---
title: Get attribution information
description: Listen for attribution changes using the Adjust SDK
slug: en/sdk/cocos2dx/features/attribution
slug: en/sdk/cocos2dx/v4/features/attribution
versions:
- label: v5
value: v5
default: true
- label: v4
value: v4
redirects:
v5: /en/sdk/cocos2dx/features/attribution
---

When a user interacts with an Adjust link, their attribution information updates. This can happen if the user interacts with a [deep link](https://help.adjust.com/en/article/deep-links). Information about a user's attribution is represented in the `AdjustAttribution2dx` class.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
---
title: Send callback information
description: Use these methods to send callback information to Adjust.
slug: en/sdk/cocos2dx/features/callbacks
slug: en/sdk/cocos2dx/v4/features/callbacks
versions:
- label: v5
value: v5
default: true
- label: v4
value: v4
redirects:
v5: /en/sdk/cocos2dx/features/callbacks
---

Set up callbacks to trigger functions when the SDK sends information to Adjust. You can set up callbacks for **sessions** and **events**.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@
title: Deep linking
description: Follow the guides in this section to set up deep linking.
category-title: Deep linking
slug: en/sdk/cocos2dx/features/deep-links
slug: en/sdk/cocos2dx/v4/features/deep-links
versions:
- label: v5
value: v5
default: true
- label: v4
value: v4
redirects:
v5: /en/sdk/cocos2dx/features/deep-links
---

You can create deep links to take users to specific pages in your app. The Adjust SDK uses different logic depending on if the user already has your app installed on their device:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
---
title: Get device information
description: Use these methods to add details to your callbacks and improve your reporting.
slug: en/sdk/cocos2dx/features/device-info
slug: en/sdk/cocos2dx/v4/features/device-info
versions:
- label: v5
value: v5
default: true
- label: v4
value: v4
redirects:
v5: /en/sdk/cocos2dx/features/device-info
---

The Adjust SDK contains helper methods that return device information. Use these methods to add details to your callbacks and improve your reporting.
Expand Down
Loading

0 comments on commit ac24c2a

Please sign in to comment.